import { Controller, Get, Post, Patch, Param, Body, Query } from '@nestjs/common'
import { HearingsService } from './hearings.service'
import { CreateHearingDto } from './dto/create-hearing.dto'
import { UpdateHearingDto } from './dto/update-hearing.dto'

@Controller('hearings')
export class HearingsController {
  constructor(private readonly service: HearingsService) {}

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

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

  @Get('upcoming')
  upcoming(@Query('days') days?: string) {
    return this.service.findUpcoming(days ? parseInt(days) : 7)
  }

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

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

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