import { Controller, Get, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { CurrentUser } from '@tria-plc/api-common/modules/auth/decorators/current-user.decorator';
import { JwtGuard } from '@tria-plc/api-common/modules/auth/services/jwt.guard';
import type { TCurrentUser } from '@tria-plc/api-common/modules/auth/types/current-user.type';

import { FreightMeService } from './freight-me.service';

@ApiTags('auth')
@Controller('me')
@ApiBearerAuth()
export class FreightMeController {
  constructor(private readonly freightMeService: FreightMeService) {}

  @Get()
  @UseGuards(JwtGuard)
  @ApiOperation({
    summary: 'Current user with flat permissionKeys for backoffice gating',
  })
  getMe(@CurrentUser() user: TCurrentUser) {
    return this.freightMeService.getEnrichedProfile(user);
  }
}
