// billing.module.ts

import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import Stripe from 'stripe';
import { Enrollment } from '../enrollments/enrollment.entity';
import { Course } from '../course/course.entity';
import { BillingService } from './billing.service';
import { BillingController } from './billing.controller';
import { ConfigService } from '@nestjs/config';

@Module({
  imports: [TypeOrmModule.forFeature([Enrollment, Course])],
  providers: [
    BillingService,
    {
      provide: 'STRIPE',
      useFactory: (config: ConfigService) => {
        const stripeSecret = config.get<string>('STRIPE_SECRET');
        if (!stripeSecret) {
          throw new Error('STRIPE_SECRET environment variable is not set');
        }
        return new Stripe(stripeSecret, { apiVersion: '2026-02-25.clover' as any });
      },
      inject: [ConfigService],
    },
  ],
  controllers: [BillingController],
})
export class BillingModule { }
