import {
  Body, Controller, Delete, Get, HttpCode, HttpStatus,
  Param, ParseUUIDPipe, Patch, Post, Query,
} from '@nestjs/common';
import { RuleEngineManage, RuleEngineView } from '../../../common/rule-engine-guards';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { CreateSurchargeTypeDto } from '../dto/create-surcharge-type.dto';
import { UpdateSurchargeTypeDto } from '../dto/update-surcharge-type.dto';
import { SurchargeTypesService } from '../services/surcharge-types.service';

@ApiTags('surcharge-types')
@Controller('surcharge-types')
@ApiBearerAuth()
export class SurchargeTypesController {
  constructor(private readonly service: SurchargeTypesService) {}

  @Get()
  @RuleEngineView('surcharge-types')
  @ApiOperation({ summary: 'List surcharge types' })
  findAll(@Query() query: Record<string, string>) {
    return this.service.findAll({
      isActive: query['isActive'] !== undefined ? query['isActive'] === 'true' : undefined,
      page: query['page'] ? parseInt(query['page'], 10) : undefined,
      pageSize: query['pageSize'] ? parseInt(query['pageSize'], 10) : undefined,
    });
  }

  @Get(':id')
  @RuleEngineView('surcharge-types')
  @ApiOperation({ summary: 'Get a surcharge type by ID' })
  findOne(@Param('id', ParseUUIDPipe) id: string) {
    return this.service.findById(id);
  }

  @Post()
  @RuleEngineManage('surcharge-types')
  @ApiOperation({ summary: 'Create a surcharge type' })
  create(@Body() dto: CreateSurchargeTypeDto) {
    return this.service.create(dto);
  }

  @Patch(':id')
  @RuleEngineManage('surcharge-types')
  @ApiOperation({ summary: 'Update a surcharge type' })
  update(@Param('id', ParseUUIDPipe) id: string, @Body() dto: UpdateSurchargeTypeDto) {
    return this.service.update(id, dto);
  }

  @Delete(':id')
  @RuleEngineManage('surcharge-types')
  @HttpCode(HttpStatus.NO_CONTENT)
  @ApiOperation({ summary: 'Soft-delete a surcharge type' })
  remove(@Param('id', ParseUUIDPipe) id: string) {
    return this.service.remove(id);
  }
}
