import {
  Controller, Get, Post, Put, Delete,
  Param, Body, Query, UseGuards,
} from '@nestjs/common';
import { ApiTags, ApiBearerAuth, ApiOperation, ApiQuery } from '@nestjs/swagger';
import { IamGuard } from '../../common/iam-adapter';
import { Roles } from '../../common/roles.decorator';
import { SegmentFareService } from './segment-fare.service';
import { CreateSegmentFareDto, UpdateSegmentFareDto } from './segment-fare.dto';

@ApiTags('Admin – Segment Fares')
@Controller('admin/segment-fares')
@ApiBearerAuth('IAM-auth')
@UseGuards(IamGuard)
@Roles('ADMIN', 'SUPERVISOR')
export class SegmentFareController {
  constructor(private readonly service: SegmentFareService) {}

  @Get()
  @ApiOperation({ summary: 'List all segment fare rules, optionally filtered by route' })
  @ApiQuery({ name: 'routeId', required: false })
  findAll(@Query('routeId') routeId?: string) {
    return this.service.findAll(routeId);
  }

  @Get(':id')
  @ApiOperation({ summary: 'Get a single segment fare rule' })
  findOne(@Param('id') id: string) {
    return this.service.findOne(id);
  }

  @Post()
  @ApiOperation({ summary: 'Create a segment fare rule' })
  create(@Body() dto: CreateSegmentFareDto) {
    return this.service.create(dto);
  }

  @Put(':id')
  @ApiOperation({ summary: 'Update a segment fare rule' })
  update(@Param('id') id: string, @Body() dto: UpdateSegmentFareDto) {
    return this.service.update(id, dto);
  }

  @Delete(':id')
  @ApiOperation({ summary: 'Delete a segment fare rule' })
  remove(@Param('id') id: string) {
    return this.service.remove(id);
  }
}
