import {
  Body,
  Controller,
  Delete,
  Param,
  Patch,
  Post,
  Put,
} from '@nestjs/common';
import { ReconciliationDataOrchestrator } from '../domain/usecases/reconciliation-data.orchestrator';
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
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';
import { TransactionEntity } from '../../transaction/domain/entities/transaction.entity';
import { UpdateReconciliationDto } from './dto/reconciliation.dto';
import { RecapReconciliationDto } from './dto/recap.dto';
import { OtpVerifyDto } from './dto/cancel-top-dto';

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

  @Post('/recap-transaction')
  async recap(@Body() body: RecapReconciliationDto): Promise<any> {
    return await this.orchestrator.recap(body);
  }

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

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

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

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

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