import { Controller, Get, Post, Patch, Param, Body, Query } from '@nestjs/common'
import { MattersService } from './matters.service'
import { CreateMatterDto } from './dto/create-matter.dto'
import { UpdateMatterDto } from './dto/update-matter.dto'

@Controller('matters')
export class MattersController {
  constructor(private readonly service: MattersService) {}

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

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

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

  @Patch(':id')
  update(@Param('id') id: string, @Body() dto: UpdateMatterDto) {
    return this.service.update(id, dto)
  }

  @Post(':id/close')
  close(@Param('id') id: string, @Body('outcome') outcome: string) {
    return this.service.close(id, outcome)
  }
}
