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

import { BillingController } from './billing.controller';
import { BillingAdminController } from './billing-admin.controller';
import { BillingService } from './billing.service';
// ClientAuthGuard only needs Reflector + the scheme_dbs DataSource (both global),
// so we can provide it here without importing the whole ClientPortalModule.
import { ClientAuthGuard } from '../guards/client-auth.guard';
import { ClientSubscription } from './entities/client-subscription.entity';
// HARDENING #3: idempotency table for Stripe webhook events
import { StripeEvent } from './entities/stripe-event.entity';
import { Company } from '../../companies/entities/company.entity';

@Module({
  imports: [
    ConfigModule,
    TypeOrmModule.forFeature([ClientSubscription, StripeEvent, Company], 'scheme_dbs'),
  ],
  controllers: [
    BillingController,       // client-facing: checkout, status, webhook
    BillingAdminController,  // admin/superadmin: set-price, grant-free, mark-paid, revoke
  ],
  providers: [BillingService, ClientAuthGuard],
  exports: [BillingService], // exported so the login gate can use it later
})
export class BillingModule {}
