import {
  Controller,
  Get,
  Post,
  Delete,
  Body,
  Param,
  ParseIntPipe,
} from '@nestjs/common';
import { UserProductsService } from './user-products.service';
import { UpsertUserProductDto } from './dto/upsert-user-product.dto';
import { CurrentUser } from '../auth/decorators/current-user.decorator';

@Controller('user-products')
export class UserProductsController {
  constructor(private readonly service: UserProductsService) {}

  @Get()
  findAll(@CurrentUser() user: { userId: number }) {
    return this.service.findAll(user.userId);
  }

  @Post()
  upsert(
    @CurrentUser() user: { userId: number },
    @Body() dto: UpsertUserProductDto,
  ) {
    return this.service.upsert(user.userId, dto);
  }

  @Delete(':productId')
  remove(
    @CurrentUser() user: { userId: number },
    @Param('productId', ParseIntPipe) productId: number,
  ) {
    return this.service.remove(user.userId, productId);
  }
}
