import { Controller, Get, Post, Patch, Delete, Param, Body, Query } from '@nestjs/common'
import { ExpensesService } from './expenses.service'
import { CreateExpenseDto } from './dto/create-expense.dto'

@Controller('expenses')
export class ExpensesController {
  constructor(private readonly service: ExpensesService) {}

  @Post()
  create(@Body() dto: CreateExpenseDto) {
    return this.service.create(dto)
  }

  @Get()
  findAll(
    @Query('clientFolderId') clientFolderId?: string,
    @Query('matterId')       matterId?:       string,
    @Query('status')         status?:         string,
    @Query('billable')       billable?:       string,
    @Query('limit')          limit?:          string,
    @Query('offset')         offset?:         string,
  ) {
    return this.service.findAll({
      clientFolderId, matterId, status, billable,
      limit:  limit  ? parseInt(limit)  : undefined,
      offset: offset ? parseInt(offset) : undefined,
    })
  }

  @Post('mark-billed')
  markBilled(@Body('ids') ids: string[], @Body('invoiceId') invoiceId: string) {
    return this.service.markBilled(ids, invoiceId)
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.service.findOne(id)
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() dto: Partial<CreateExpenseDto>) {
    return this.service.update(id, dto)
  }

  @Delete(':id')
  delete(@Param('id') id: string) {
    return this.service.delete(id)
  }
}
