import {
  Body,
  Controller,
  Delete,
  Param,
  Patch,
  Post,
  Put,
} from '@nestjs/common';
import { RefundDataOrchestrator } from '../domain/usecases/refund-data.orchestrator';
import { RefundDto } from './dto/refund.dto';
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { RefundEntity } from '../domain/entities/refund.entity';
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
import { BatchIdsDto } from 'src/core/modules/infrastructure/dto/base-batch.dto';
import { Public } from 'src/core/guards';

@ApiTags(`${MODULE_NAME.REFUND.split('-').join(' ')} - data`)
@Controller(`v1/${MODULE_NAME.REFUND}`)
@Public(false)
@ApiBearerAuth('JWT')
export class RefundDataController {
  constructor(private orchestrator: RefundDataOrchestrator) {}

  @Post()
  async create(@Body() data: RefundDto): Promise<RefundEntity> {
    return await this.orchestrator.create(data);
  }

  @Put('/batch-delete')
  async batchDeleted(@Body() body: BatchIdsDto): Promise<BatchResult> {
    return await this.orchestrator.batchDelete(body.ids);
  }

  @Patch(':id/cancel')
  async cancel(@Param('id') dataId: string): Promise<string> {
    return await this.orchestrator.cancel(dataId);
  }

  @Put('/batch-cancel')
  async batchcancel(@Body() body: BatchIdsDto): Promise<BatchResult> {
    return await this.orchestrator.batchCancel(body.ids);
  }

  @Patch(':id/confirm')
  async confirm(@Param('id') dataId: string): Promise<string> {
    return await this.orchestrator.confirm(dataId);
  }

  @Put('/batch-confirm')
  async batchConfirm(@Body() body: BatchIdsDto): Promise<BatchResult> {
    return await this.orchestrator.batchConfirm(body.ids);
  }

  @Put(':id')
  async update(
    @Param('id') dataId: string,
    @Body() data: RefundDto,
  ): Promise<RefundEntity> {
    return await this.orchestrator.update(dataId, data);
  }

  @Delete(':id')
  async delete(@Param('id') dataId: string): Promise<string> {
    return await this.orchestrator.delete(dataId);
  }
}
