import { Controller, HttpCode, Post, RawBodyRequest, Req } from '@nestjs/common'
import { ApiOperation, ApiTags } from '@nestjs/swagger'
import { FastifyRequest } from 'fastify'
import { BillingService } from '../services'

@Controller('billing')
@ApiTags('default', 'webhook')
export class WebhookController {
	constructor(private readonly _billingService: BillingService) {}

	@Post('stripe/webhook')
	@HttpCode(200)
	@ApiOperation({ description: 'Handles Stripe webhook events' })
	async handleStripeWebhook(@Req() request: RawBodyRequest<FastifyRequest>): Promise<void> {
		await this._billingService.handleStripeWebhook(request.rawBody!, request.headers)
	}
}
