import { Body, Controller, Get, Param, Post } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { TenantId } from '../common/tenant-id.decorator'; import { RequireRecentAuthentication } from '../auth/require-recent-authentication.decorator'; import { CurrentSessionUserId } from '../auth/current-session-user.decorator'; import { BillingService, BillingActionDto, CreateManualRechargeDto, ManualRechargePreflightDto, CreateBillingRuleDto, CreateSmsBillingRecordDto, CreateTenantAccountDto, EstimateSmsCostDto, UpdateCreditLimitDto, } from './billing.service'; @ApiTags('billing') @Controller('admin/billing') export class BillingController { constructor(private readonly billing: BillingService) {} @Get('accounts') listAccounts() { return this.billing.listAccounts(); } @Post('accounts') createAccount(@Body() body: CreateTenantAccountDto) { return this.billing.createAccount(body); } @Post('accounts/:tenantId/credit-limit') @RequireRecentAuthentication() updateCreditLimit(@Param('tenantId') tenantId: string, @Body() body: UpdateCreditLimitDto) { return this.billing.updateCreditLimit(tenantId, body); } @Get('recharges') listRechargeOrders(@TenantId() tenantId?: string) { return this.billing.listRechargeOrders(tenantId); } @Get('manual-recharges') listManualRechargeRecords(@TenantId() tenantId?: string) { return this.billing.listManualRechargeRecords(tenantId); } @Post('manual-recharges') @RequireRecentAuthentication() createManualRecharge(@Body() body: CreateManualRechargeDto, @CurrentSessionUserId() operatorId?: string) { return this.billing.createManualRecharge({ ...body, operatorId }); } @Post('manual-recharges/preflight') manualRechargePreflight(@Body() body: ManualRechargePreflightDto) { return this.billing.manualRechargePreflight(body); } @Post('estimate') estimateSmsCost(@Body() body: EstimateSmsCostDto) { return this.billing.estimateSmsCost(body); } @Post('check') checkAccount(@Body() body: BillingActionDto) { return this.billing.checkAccount(body); } @Post('freeze') freeze(@Body() body: BillingActionDto) { return this.billing.freeze(body); } @Post('charge') charge(@Body() body: BillingActionDto) { return this.billing.charge(body); } @Post('release') release(@Body() body: BillingActionDto) { return this.billing.release(body); } @Post('refund') @RequireRecentAuthentication() refund(@Body() body: BillingActionDto) { return this.billing.refund(body); } @Post('adjust') @RequireRecentAuthentication() adjust(@Body() body: BillingActionDto) { return this.billing.adjust(body); } @Get('sms-billing-records') listSmsBillingRecords(@TenantId() tenantId?: string) { return this.billing.listSmsBillingRecords(tenantId); } @Post('sms-billing-records') createSmsBillingRecord(@Body() body: CreateSmsBillingRecordDto) { return this.billing.createSmsBillingRecord(body); } @Get('rules') listRules() { return this.billing.listRules(); } @Post('rules') createRule(@Body() body: CreateBillingRuleDto) { return this.billing.createRule(body); } } @ApiTags('client-billing') @Controller('client/billing') export class ClientBillingController { constructor(private readonly billing: BillingService) {} @Get('orders') listRechargeOrders(@TenantId() tenantId?: string) { return this.billing.listRechargeOrders(tenantId); } @Post('estimate') estimateSmsCost(@Body() body: EstimateSmsCostDto) { return this.billing.estimateSmsCost(body); } }