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

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

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

import type {
    MemberPaymentRepository,
    MembershipFeeRepository,
} from '@core/payments/domain/repositories/MembershipFeeRepository';
import type { PaymentRepository } from '@core/payments/domain/repositories/PaymentRepository';
import type { PrizeRepository } from '@core/payments/domain/repositories/PrizeRepository';
import type { TransactionRepository, WalletRepository } from '@core/payments/domain/repositories/WalletRepository';

import { InMemoryMemberPaymentRepository, InMemoryMembershipFeeRepository } 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): PaymentRepository => new InMemoryPaymentRepository(logger),
      inject: ['Logger'],
    },
    {
      provide: PAYMENTS_MEMBERSHIP_FEE_REPOSITORY_TOKEN,
      useFactory: (logger: Logger): MembershipFeeRepository => new InMemoryMembershipFeeRepository(logger),
      inject: ['Logger'],
    },
    {
      provide: PAYMENTS_MEMBER_PAYMENT_REPOSITORY_TOKEN,
      useFactory: (logger: Logger): MemberPaymentRepository => new InMemoryMemberPaymentRepository(logger),
      inject: ['Logger'],
    },
    {
      provide: PAYMENTS_PRIZE_REPOSITORY_TOKEN,
      useFactory: (logger: Logger): PrizeRepository => new InMemoryPrizeRepository(logger),
      inject: ['Logger'],
    },
    {
      provide: PAYMENTS_WALLET_REPOSITORY_TOKEN,
      useFactory: (logger: Logger): WalletRepository => new InMemoryWalletRepository(logger),
      inject: ['Logger'],
    },
    {
      provide: PAYMENTS_TRANSACTION_REPOSITORY_TOKEN,
      useFactory: (logger: Logger): TransactionRepository => 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 {}
