import { Controller, Get, Post, Patch, Delete, Body, Param, Query } from '@nestjs/common';
import { DemandasService } from './demandas.service';

@Controller('demandas')
export class DemandasController {
  constructor(private svc: DemandasService) {}

  @Get() findAll(@Query() query: any) { return this.svc.findAll(query); }
  @Get(':id') findOne(@Param('id') id: string) { return this.svc.findOne(id); }
  @Post() create(@Body() body: any) { return this.svc.create(body); }
  @Patch(':id') update(@Param('id') id: string, @Body() body: any) { return this.svc.update(id, body); }
  @Delete(':id') remove(@Param('id') id: string) { return this.svc.remove(id); }

  @Post(':id/publicar') publicar(@Param('id') id: string) { return this.svc.updateStatus(id, 'aberta'); }
  @Post(':id/cancelar') cancelar(@Param('id') id: string) { return this.svc.updateStatus(id, 'cancelada'); }
  @Post(':id/enviar-cotacao') enviarCotacao(@Param('id') id: string) { return this.svc.updateStatus(id, 'em_cotacao'); }

  @Get(':id/itens-linha') itens(@Param('id') id: string) { return this.svc.findItens(id); }
  @Post(':id/itens-linha') createItem(@Param('id') id: string, @Body() body: any) {
    return this.svc.createItem({ ...body, demanda_id: id });
  }
  @Patch(':id/itens-linha/:itemId') updateItem(@Param('itemId') itemId: string, @Body() body: any) {
    return this.svc.updateItem(itemId, body);
  }
  @Delete(':id/itens-linha/:itemId') removeItem(@Param('itemId') itemId: string) {
    return this.svc.removeItem(itemId);
  }
}
