import { Body, Controller, Get, Param, ParseUUIDPipe, Patch, Post } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';

import { CreateWarehouseZoneDto } from './dto/create-warehouse-zone.dto';
import { UpdateWarehouseYardDto } from './dto/update-warehouse-yard.dto';
import { WarehouseYardsService } from './warehouse-yards.service';
import { WarehouseZonesService } from './warehouse-zones.service';

@ApiTags('warehouse-yards')
@ApiBearerAuth()
@Controller('warehouse-yards')
export class WarehouseYardsController {
  constructor(
    private readonly yardsService: WarehouseYardsService,
    private readonly zonesService: WarehouseZonesService,
  ) {}

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

  @Patch(':id')
  @ApiOperation({ summary: 'Update warehouse yard' })
  update(@Param('id', ParseUUIDPipe) id: string, @Body() dto: UpdateWarehouseYardDto) {
    return this.yardsService.update(id, dto);
  }

  @Get(':yardId/zones')
  @ApiOperation({ summary: 'List zones within a yard' })
  listZones(@Param('yardId', ParseUUIDPipe) yardId: string) {
    return this.zonesService.findByYard(yardId);
  }

  @Post(':yardId/zones')
  @ApiOperation({ summary: 'Create a zone within a yard' })
  createZone(
    @Param('yardId', ParseUUIDPipe) yardId: string,
    @Body() dto: CreateWarehouseZoneDto,
  ) {
    return this.zonesService.create(yardId, dto);
  }
}
