import { Controller, Get, Post, Put, Delete, Param, Body, UseGuards } from '@nestjs/common';
import { RbacGuard } from '../auth/guards/rbac.guard';
import { Permissions } from '../auth/decorators/permissions.decorator';
import { ProductionLineService } from '../services/production-line.service';
import { CreateProductionLineDto } from '../dto/create-production-line.dto';
import { UpdateProductionLineDto } from '../dto/update-production-line.dto';

@Controller('production-lines')
export class ProductionLineController {
  constructor(private readonly productionLineService: ProductionLineService) {}

  @Get()
  @Permissions('manager:production')
  @UseGuards(RbacGuard)
  async findAll() {
    return this.productionLineService.findAll();
  }

  @Get(':id')
  @Permissions('manager:production')
  @UseGuards(RbacGuard)
  async findOne(@Param('id') id: string) {
    return this.productionLineService.findOne(id);
  }

  @Post()
  @Permissions('manager:production')
  @UseGuards(RbacGuard)
  async create(@Body() createDto: CreateProductionLineDto) {
    return this.productionLineService.create(createDto);
  }

  @Put(':id')
  @Permissions('manager:production')
  @UseGuards(RbacGuard)
  async update(
    @Param('id') id: string,
    @Body() updateDto: UpdateProductionLineDto,
  ) {
    return this.productionLineService.update(id, updateDto);
  }

  @Delete(':id')
  @Permissions('manager:production')
  @UseGuards(RbacGuard)
  async remove(@Param('id') id: string) {
    return this.productionLineService.remove(id);
  }

  @Get('type/:type')
  @Permissions('manager:production')
  @UseGuards(RbacGuard)
  async findByType(@Param('type') type: string) {
    return this.productionLineService.findByType(type);
  }

  @Get('status/:status')
  @Permissions('manager:production')
  @UseGuards(RbacGuard)
  async findByStatus(@Param('status') status: string) {
    return this.productionLineService.findByStatus(status);
  }

  @Get('capacity/:type')
  @Permissions('manager:production')
  @UseGuards(RbacGuard)
  async getCapacityByType(@Param('type') type: string) {
    return this.productionLineService.getCapacityByType(type);
  }

  @Get('available/:type')
  @Permissions('manager:production')
  @UseGuards(RbacGuard)
  async getAvailableLines(@Param('type') type: string) {
    return this.productionLineService.getAvailableLines(type);
  }
}
