import { ForbiddenException, Injectable } from '@nestjs/common';

const flag = (name: string) => String(process.env[name] ?? 'false').toLowerCase() === 'true';

@Injectable()
export class ComplianceService {
  getFlags() {
    return {
      liveInvestment: flag('LIVE_INVESTMENT'),
      collectFunds: flag('COLLECT_FUNDS'),
      livePayments: flag('LIVE_PAYMENTS')
    } as const;
  }

  assertLiveInvestmentAllowed() {
    if (!this.getFlags().liveInvestment) {
      throw new ForbiddenException('LIVE_INVESTMENT_DISABLED');
    }
  }

  assertCollectFundsAllowed() {
    if (!this.getFlags().collectFunds) {
      throw new ForbiddenException('COLLECT_FUNDS_DISABLED');
    }
  }

  assertLivePaymentsAllowed() {
    if (!this.getFlags().livePayments) {
      throw new ForbiddenException('LIVE_PAYMENTS_DISABLED');
    }
  }
}
