import {
  Controller,
  Get,
  Post,
  Put,
  Patch,
  Delete,
  Body,
  Param,
  Query,
  ParseUUIDPipe,
  HttpCode,
  HttpStatus,
} from '@nestjs/common';
import { PricingDetailService } from './pricing-detail.service';
import {
  CreatePricingDetailDto,
  UpdatePricingDetailDto,
  UpdatePriceDto,
} from './dto/pricing-detail.dto';
import { BootstrapTableRequestDto } from '../commons/dto/bootstrap-table-request.dto'

@Controller('settings/pricing-details')
export class PricingDetailController {
  constructor(private readonly service: PricingDetailService) {}

  @Get()
  findAll(
    @Query() pagination: BootstrapTableRequestDto,
    @Query('headerId') headerId?: string,
    @Query('itemTypeId') itemTypeId?: string,
  ) {
    return this.service.findAll(pagination, headerId, itemTypeId);
  }

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

  @Get('active/:headerId')
  findActive(@Param('headerId', ParseUUIDPipe) headerId: string) {
    return this.service.findActiveByHeader(headerId);
  }

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

  @Put(':id')
  update(
    @Param('id', ParseUUIDPipe) id: string,
    @Body() dto: UpdatePricingDetailDto,
  ) {
    return this.service.update(id, dto);
  }

  @Patch(':headerId/update-price')
  updatePrice(
    @Param('headerId', ParseUUIDPipe) headerId: string,
    @Body() dto: UpdatePriceDto,
  ) {
    return this.service.updatePrice(headerId, dto);
  }

  @Delete(':id')
  @HttpCode(HttpStatus.NO_CONTENT)
  remove(@Param('id', ParseUUIDPipe) id: string) {
    return this.service.remove(id);
  }
}