import { Body, Controller, Get, Headers, Param, Post } from '@nestjs/common';
import { CreatePublicPaymentIntentDto } from './dto/create-public-payment-intent.dto';
import { PaymentsService } from './payments.service';

@Controller('payments')
export class PublicPaymentsController {
  constructor(private readonly paymentsService: PaymentsService) {}

  @Post('public/intent')
  createIntent(@Body() body: CreatePublicPaymentIntentDto) {
    return this.paymentsService.createPublicIntent(body);
  }

  @Get('public/order/:orderId/status')
  orderStatus(@Param('orderId') orderId: string) {
    return this.paymentsService.getPublicPaymentStatus(orderId);
  }

  @Post('webhooks/mercado-pago')
  mercadoPagoWebhook(
    @Body() body: Record<string, unknown>,
    @Headers('x-signature') signature?: string,
    @Headers('x-request-id') requestId?: string,
  ) {
    return this.paymentsService.handleMercadoPagoWebhook(body, signature, requestId);
  }

  @Post('webhooks/stripe')
  stripeWebhook(
    @Body() body: Record<string, unknown>,
    @Headers('stripe-signature') signature?: string,
  ) {
    return this.paymentsService.handleStripeWebhook(body, signature);
  }
}
