import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  ParseIntPipe,
  Patch,
  Post,
} from '@nestjs/common';
import { ReceiptAliasService } from './receipt-alias.service';
import { CreateReceiptAliasDto } from './dto/create-receipt-alias.dto';
import { UpdateReceiptAliasDto } from './dto/update-receipt-alias.dto';
import { CurrentUser } from '../auth/decorators/current-user.decorator';

@Controller('receipt-aliases')
export class ReceiptAliasController {
  constructor(private readonly receiptAliasService: ReceiptAliasService) {}

  @Get()
  findAll(@CurrentUser() user: { userId: number; role: string }) {
    return this.receiptAliasService.findAllForUser(user.userId, user.role);
  }

  @Post()
  upsert(
    @Body() dto: CreateReceiptAliasDto,
    @CurrentUser() user: { userId: number; role: string },
  ) {
    return this.receiptAliasService.upsert(dto, user.userId, user.role);
  }

  @Patch(':id')
  update(
    @Param('id', ParseIntPipe) id: number,
    @Body() dto: UpdateReceiptAliasDto,
    @CurrentUser() user: { userId: number; role: string },
  ) {
    return this.receiptAliasService.update(id, dto, user.userId, user.role);
  }

  @Delete(':id')
  remove(
    @Param('id', ParseIntPipe) id: number,
    @CurrentUser() user: { userId: number; role: string },
  ) {
    return this.receiptAliasService.remove(id, user.userId, user.role);
  }
}
