import {
  Body,
  Controller,
  Delete,
  Get,
  HttpCode,
  HttpStatus,
  Param,
  ParseUUIDPipe,
  Patch,
  Post,
  Query,
} from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { RuleEngineCreate, RuleEngineDelete, RuleEngineUpdate } from '../../../common/rule-engine-guards';
import { StaffReference } from '../../../common/booking-guards';
import { CreateYardDistanceDto } from '../dto/create-yard-distance.dto';
import { ListYardDistancesQueryDto } from '../dto/list-rule-engine-query.dto';
import { UpdateYardDistanceDto } from '../dto/update-yard-distance.dto';
import { YardDistancesService } from '../services/yard-distances.service';

@ApiTags('yard-distances')
@Controller('yard-distances')
@ApiBearerAuth()
export class YardDistancesController {
  constructor(private readonly service: YardDistancesService) {}

  @Get()
  @StaffReference()
  @ApiOperation({ summary: 'List yard distances' })
  findAll(@Query() query: ListYardDistancesQueryDto) {
    return this.service.findAll(query);
  }

  @Get(':id')
  @StaffReference()
  @ApiOperation({ summary: 'Get a yard distance by ID' })
  findOne(@Param('id', ParseUUIDPipe) id: string) {
    return this.service.findById(id);
  }

  @Post()
  @RuleEngineCreate('yard-distances')
  @ApiOperation({ summary: 'Create a yard distance' })
  create(@Body() dto: CreateYardDistanceDto) {
    return this.service.create(dto);
  }

  @Patch(':id')
  @RuleEngineUpdate('yard-distances')
  @ApiOperation({ summary: 'Update a yard distance' })
  update(@Param('id', ParseUUIDPipe) id: string, @Body() dto: UpdateYardDistanceDto) {
    return this.service.update(id, dto);
  }

  @Delete(':id')
  @RuleEngineDelete('yard-distances')
  @HttpCode(HttpStatus.NO_CONTENT)
  @ApiOperation({ summary: 'Soft-delete a yard distance' })
  remove(@Param('id', ParseUUIDPipe) id: string) {
    return this.service.remove(id);
  }
}
