import { Injectable } from '@nestjs/common';
import { CreateRefundManager } from './managers/create-refund.manager';
import { RefundDataService } from '../../data/services/refund-data.service';
import { RefundEntity } from '../entities/refund.entity';
import { DeleteRefundManager } from './managers/delete-refund.manager';
import { UpdateRefundManager } from './managers/update-refund.manager';
import { ConfirmRefundManager } from './managers/confirm-refund.manager';
import { STATUS } from 'src/core/strings/constants/base.constants';
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
import { BatchConfirmRefundManager } from './managers/batch-confirm-refund.manager';
import { BatchDeleteRefundManager } from './managers/batch-delete-refund.manager';
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { CancelRefundManager } from './managers/cancel-refund.manager';
import { BatchCancelRefundManager } from './managers/batch-cancel-refund.manager';
import { TransactionDataService } from 'src/modules/transaction/transaction/data/services/transaction-data.service';

@Injectable()
export class RefundDataOrchestrator {
  constructor(
    private createManager: CreateRefundManager,
    private updateManager: UpdateRefundManager,
    private deleteManager: DeleteRefundManager,
    private cancelManager: CancelRefundManager,
    private confirmManager: ConfirmRefundManager,
    private batchDeleteManager: BatchDeleteRefundManager,
    private batchCancelManager: BatchCancelRefundManager,
    private batchConfirmManager: BatchConfirmRefundManager,
    private serviceData: RefundDataService,
    private transactionDataService: TransactionDataService,
  ) {}

  async create(data): Promise<RefundEntity> {
    this.createManager.setData(data);
    this.createManager.setService(
      this.serviceData,
      TABLE_NAME.REFUND,
      this.transactionDataService,
    );
    await this.createManager.execute();
    return this.createManager.getResult();
  }

  async update(dataId, data): Promise<RefundEntity> {
    this.updateManager.setData(dataId, data);
    this.updateManager.setService(
      this.serviceData,
      TABLE_NAME.REFUND,
      this.transactionDataService,
    );
    await this.updateManager.execute();
    return this.updateManager.getResult();
  }

  async delete(dataId): Promise<string> {
    this.deleteManager.setData(dataId);
    this.deleteManager.setService(this.serviceData, TABLE_NAME.REFUND);
    await this.deleteManager.execute();
    return this.deleteManager.getResult();
  }

  async batchDelete(dataIds: string[]): Promise<BatchResult> {
    this.batchDeleteManager.setData(dataIds);
    this.batchDeleteManager.setService(this.serviceData, TABLE_NAME.REFUND);
    await this.batchDeleteManager.execute();
    return this.batchDeleteManager.getResult();
  }

  async cancel(dataId): Promise<string> {
    this.cancelManager.setData(dataId, STATUS.CANCEL);
    this.cancelManager.setService(this.serviceData, TABLE_NAME.REFUND);
    await this.cancelManager.execute();
    return this.cancelManager.getResult();
  }

  async batchCancel(dataIds: string[]): Promise<BatchResult> {
    this.batchCancelManager.setData(dataIds, STATUS.CANCEL);
    this.batchCancelManager.setService(this.serviceData, TABLE_NAME.REFUND);
    await this.batchCancelManager.execute();
    return this.batchCancelManager.getResult();
  }

  async confirm(dataId): Promise<string> {
    this.confirmManager.setData(dataId, STATUS.PENDING);
    this.confirmManager.setService(this.serviceData, TABLE_NAME.REFUND);
    await this.confirmManager.execute();
    return this.confirmManager.getResult();
  }

  async batchConfirm(dataIds: string[]): Promise<BatchResult> {
    this.batchConfirmManager.setData(dataIds, STATUS.PENDING);
    this.batchConfirmManager.setService(this.serviceData, TABLE_NAME.REFUND);
    await this.batchConfirmManager.execute();
    return this.batchConfirmManager.getResult();
  }
}
