import { Controller, Get, Post, Body, Param } from '@nestjs/common';
import { CouponService } from './coupon.service';
import { Public } from '../auth/public.decorator';

@Controller('coupons')
export class CouponsController {
  constructor(private readonly couponService: CouponService) {}

  @Public()
  @Get('list')
  async getCoupons() {
    const coupons = await this.couponService.findAll();
    return { coupons };
  }

  @Public()
  @Post('create')
  async createCoupon(@Body() body: any) {
    const coupon = await this.couponService.create(body);
    return { success: true, coupon };
  }

  @Public()
  @Post('update/:id')
  async updateCoupon(@Param('id') id: number, @Body() body: any) {
    const coupon = await this.couponService.update(id, body);
    return { success: true, coupon };
  }

  @Public()
  @Post('delete/:id')
  async deleteCoupon(@Param('id') id: number) {
    await this.couponService.delete(id);
    return { success: true };
  }
}
