/**
 * Subscriptions Module
 *
 * Provides subscription and license management endpoints.
 */

import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule } from '@nestjs/config';

// Controller
import { SubscriptionsController } from '../controllers/subscriptions.controller';

// Service
import { SubscriptionService } from '../services/subscription.service';

// ORM Entities
import { SubscriptionOrmEntity } from '@infrastructure/persistence/typeorm/entities/subscription.orm-entity';
import { LicenseOrmEntity } from '@infrastructure/persistence/typeorm/entities/license.orm-entity';
import { OrganizationOrmEntity } from '@infrastructure/persistence/typeorm/entities/organization.orm-entity';
import { UserOrmEntity } from '@infrastructure/persistence/typeorm/entities/user.orm-entity';

// Repositories
import { TypeOrmSubscriptionRepository } from '@infrastructure/persistence/typeorm/repositories/typeorm-subscription.repository';
import { TypeOrmLicenseRepository } from '@infrastructure/persistence/typeorm/repositories/typeorm-license.repository';
import { TypeOrmOrganizationRepository } from '@infrastructure/persistence/typeorm/repositories/typeorm-organization.repository';
import { TypeOrmUserRepository } from '@infrastructure/persistence/typeorm/repositories/typeorm-user.repository';

// Repository tokens
import { SUBSCRIPTION_REPOSITORY } from '@domain/ports/out/subscription.repository';
import { LICENSE_REPOSITORY } from '@domain/ports/out/license.repository';
import { ORGANIZATION_REPOSITORY } from '@domain/ports/out/organization.repository';
import { USER_REPOSITORY } from '@domain/ports/out/user.repository';

// Stripe
import { StripeModule } from '@infrastructure/stripe/stripe.module';

@Module({
  imports: [
    ConfigModule,
    TypeOrmModule.forFeature([
      SubscriptionOrmEntity,
      LicenseOrmEntity,
      OrganizationOrmEntity,
      UserOrmEntity,
    ]),
    StripeModule,
  ],
  controllers: [SubscriptionsController],
  providers: [
    SubscriptionService,
    {
      provide: SUBSCRIPTION_REPOSITORY,
      useClass: TypeOrmSubscriptionRepository,
    },
    {
      provide: LICENSE_REPOSITORY,
      useClass: TypeOrmLicenseRepository,
    },
    {
      provide: ORGANIZATION_REPOSITORY,
      useClass: TypeOrmOrganizationRepository,
    },
    {
      provide: USER_REPOSITORY,
      useClass: TypeOrmUserRepository,
    },
  ],
  exports: [SubscriptionService, SUBSCRIPTION_REPOSITORY, LICENSE_REPOSITORY],
})
export class SubscriptionsModule {}
