import { Body, Controller, Get, Param, Post, Query, UseGuards } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { AgentsService } from './agents.service';
import { CreateAgentBookingDto, OpenShiftDto, CloseShiftDto } from './agents.dto';
import { IamGuard, IamRoles } from '../../common/iam-adapter';
import { UserRole } from '@prisma/client';

@ApiTags('Agents')
@Controller('agents')
@UseGuards(IamGuard)
@ApiBearerAuth('IAM-auth')
export class AgentsController {
  constructor(private service: AgentsService) {}

  @Post('bookings')
  @IamRoles('AGENT', 'ADMIN')
  @ApiOperation({ summary: 'Create agent booking with cash payment' })
  createBooking(@Body() dto: CreateAgentBookingDto) {
    return this.service.createAgentBooking(dto);
  }

  @Post('shifts/open')
  @IamRoles('AGENT', 'ADMIN')
  @ApiOperation({ summary: 'Open agent shift' })
  openShift(@Body() dto: OpenShiftDto) {
    return this.service.openShift(dto);
  }

  @Post('shifts/close')
  @IamRoles('AGENT', 'ADMIN')
  @ApiOperation({ summary: 'Close agent shift' })
  closeShift(@Body() dto: CloseShiftDto) {
    return this.service.closeShift(dto);
  }

  @Get(':agentId/commissions')
  @IamRoles('AGENT', 'ADMIN')
  @ApiOperation({ summary: 'Get agent commissions' })
  getCommissions(
    @Param('agentId') agentId: string,
    @Query('dateFrom') dateFrom?: string,
    @Query('dateTo') dateTo?: string
  ) {
    return this.service.getCommissions(
      agentId,
      dateFrom ? new Date(dateFrom) : undefined,
      dateTo ? new Date(dateTo) : undefined
    );
  }

  @Get(':agentId/shifts')
  @IamRoles('AGENT', 'ADMIN')
  @ApiOperation({ summary: 'Get agent shifts' })
  getShifts(@Param('agentId') agentId: string) {
    return this.service.getShifts(agentId);
  }
}
