import {
  Controller,
  Get,
  Post,
  Delete,
  Patch,
  Param,
  Body,
  UseGuards,
  ParseIntPipe,
} from '@nestjs/common';
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
import { CurrentUser } from '../../common/decorators/current-user.decorator';
import { PaymentsService } from './payments.service';
import { RegisterCardDto } from './dto/register-card.dto';
import { TossConfirmDto } from './dto/toss-confirm.dto';
import { ChargeBillingDto } from './dto/charge-billing.dto';

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

  @Get('methods')
  getMethods(@CurrentUser('id') userId: number) {
    return this.paymentsService.getMethods(userId);
  }

  @Post('methods')
  registerCard(@CurrentUser('id') userId: number, @Body() dto: RegisterCardDto) {
    return this.paymentsService.registerCard(userId, dto);
  }

  @Delete('methods/:id')
  removeCard(
    @CurrentUser('id') userId: number,
    @Param('id', ParseIntPipe) id: number,
  ) {
    return this.paymentsService.removeCard(userId, id);
  }

  @Patch('methods/:id/default')
  setDefaultCard(
    @CurrentUser('id') userId: number,
    @Param('id', ParseIntPipe) id: number,
  ) {
    return this.paymentsService.setDefaultCard(userId, id);
  }

  @Post('toss/confirm')
  confirmPayment(@Body() dto: TossConfirmDto) {
    return this.paymentsService.confirmPayment(dto);
  }

  @Post('toss/billing')
  processBilling(@Body() dto: RegisterCardDto) {
    return this.paymentsService.processBilling(dto);
  }

  @Post('charge')
  chargeBilling(
    @CurrentUser('id') userId: number,
    @Body() dto: ChargeBillingDto,
  ) {
    return this.paymentsService.chargeBilling(userId, dto);
  }
}
