import { Module } from '@nestjs/common';

import { LoggingModule } from '../../domain/logging/LoggingModule';

import type { Logger } from '@core/shared/application/Logger';

import type { IPaymentRepository } from '@core/payments/domain/repositories/IPaymentRepository';
import type {
  IMemberPaymentRepository,
  IMembershipFeeRepository,
} from '@core/payments/domain/repositories/IMembershipFeeRepository';
import type { IPrizeRepository } from '@core/payments/domain/repositories/IPrizeRepository';
import type { ITransactionRepository, IWalletRepository } from '@core/payments/domain/repositories/IWalletRepository';

import { InMemoryMembershipFeeRepository, InMemoryMemberPaymentRepository } from '@adapters/payments/persistence/inmemory/InMemoryMembershipFeeRepository';
import { InMemoryPaymentRepository } from '@adapters/payments/persistence/inmemory/InMemoryPaymentRepository';
import { InMemoryPrizeRepository } from '@adapters/payments/persistence/inmemory/InMemoryPrizeRepository';
import { InMemoryTransactionRepository, InMemoryWalletRepository } from '@adapters/payments/persistence/inmemory/InMemoryWalletRepository';

import {
  PAYMENTS_MEMBER_PAYMENT_REPOSITORY_TOKEN,
  PAYMENTS_MEMBERSHIP_FEE_REPOSITORY_TOKEN,
  PAYMENTS_PAYMENT_REPOSITORY_TOKEN,
  PAYMENTS_PRIZE_REPOSITORY_TOKEN,
  PAYMENTS_TRANSACTION_REPOSITORY_TOKEN,
  PAYMENTS_WALLET_REPOSITORY_TOKEN,
} from '../payments/PaymentsPersistenceTokens';

@Module({
  imports: [LoggingModule],
  providers: [
    {
      provide: PAYMENTS_PAYMENT_REPOSITORY_TOKEN,
      useFactory: (logger: Logger): IPaymentRepository => new InMemoryPaymentRepository(logger),
      inject: ['Logger'],
    },
    {
      provide: PAYMENTS_MEMBERSHIP_FEE_REPOSITORY_TOKEN,
      useFactory: (logger: Logger): IMembershipFeeRepository => new InMemoryMembershipFeeRepository(logger),
      inject: ['Logger'],
    },
    {
      provide: PAYMENTS_MEMBER_PAYMENT_REPOSITORY_TOKEN,
      useFactory: (logger: Logger): IMemberPaymentRepository => new InMemoryMemberPaymentRepository(logger),
      inject: ['Logger'],
    },
    {
      provide: PAYMENTS_PRIZE_REPOSITORY_TOKEN,
      useFactory: (logger: Logger): IPrizeRepository => new InMemoryPrizeRepository(logger),
      inject: ['Logger'],
    },
    {
      provide: PAYMENTS_WALLET_REPOSITORY_TOKEN,
      useFactory: (logger: Logger): IWalletRepository => new InMemoryWalletRepository(logger),
      inject: ['Logger'],
    },
    {
      provide: PAYMENTS_TRANSACTION_REPOSITORY_TOKEN,
      useFactory: (logger: Logger): ITransactionRepository => new InMemoryTransactionRepository(logger),
      inject: ['Logger'],
    },
  ],
  exports: [
    PAYMENTS_PAYMENT_REPOSITORY_TOKEN,
    PAYMENTS_MEMBERSHIP_FEE_REPOSITORY_TOKEN,
    PAYMENTS_MEMBER_PAYMENT_REPOSITORY_TOKEN,
    PAYMENTS_PRIZE_REPOSITORY_TOKEN,
    PAYMENTS_WALLET_REPOSITORY_TOKEN,
    PAYMENTS_TRANSACTION_REPOSITORY_TOKEN,
  ],
})
export class InMemoryPaymentsPersistenceModule {}
