import { Module } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs';
import { CreatePaymentHandler } from './application/commands/create-payment/create-payment.handler';
import { HandleCallbackHandler } from './application/commands/handle-callback/handle-callback.handler';
import { RefundPaymentHandler } from './application/commands/refund-payment/refund-payment.handler';
import { GetPaymentStatusHandler } from './application/queries/get-payment-status/get-payment-status.handler';
import { ListTransactionsHandler } from './application/queries/list-transactions/list-transactions.handler';
import { PAYMENT_REPOSITORY } from './domain/repositories/payment.repository';
import { PrismaPaymentRepository } from './infrastructure/repositories/prisma-payment.repository';
import { MomoService } from './infrastructure/services/momo.service';
import { PaymentGatewayFactory } from './infrastructure/services/payment-gateway.factory';
import { PAYMENT_GATEWAY_FACTORY } from './infrastructure/services/payment-gateway.interface';
import { VnpayService } from './infrastructure/services/vnpay.service';
import { ZalopayService } from './infrastructure/services/zalopay.service';
import { PaymentsController } from './presentation/controllers/payments.controller';

const CommandHandlers = [
  CreatePaymentHandler,
  HandleCallbackHandler,
  RefundPaymentHandler,
];

const QueryHandlers = [GetPaymentStatusHandler, ListTransactionsHandler];

@Module({
  imports: [CqrsModule],
  controllers: [PaymentsController],
  providers: [
    // Repositories
    { provide: PAYMENT_REPOSITORY, useClass: PrismaPaymentRepository },

    // Gateway Services
    VnpayService,
    MomoService,
    ZalopayService,
    { provide: PAYMENT_GATEWAY_FACTORY, useClass: PaymentGatewayFactory },

    // CQRS
    ...CommandHandlers,
    ...QueryHandlers,
  ],
  exports: [PAYMENT_REPOSITORY, PAYMENT_GATEWAY_FACTORY],
})
export class PaymentsModule {}
