import { Controller, Get, Post, Param, Body } from '@nestjs/common';
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
import { LicensesService } from './licenses.service';
import { ValidateKeyDto } from './dto/validate-key.dto';
import { CurrentUser } from '../../common/decorators/current-user.decorator';
import { Public } from '../../common/decorators/public.decorator';

@ApiTags('licenses')
@ApiBearerAuth()
@Controller('licenses')
export class LicensesController {
  constructor(private readonly licensesService: LicensesService) {}

  @Get(':id')
  @ApiOperation({ summary: 'Get license by ID (owner or super admin only)' })
  async findById(
    @Param('id') id: string,
    @CurrentUser('sub') userId: string,
    @CurrentUser('is_super_admin') isSuperAdmin: boolean,
  ) {
    return this.licensesService.findById(id, userId, isSuperAdmin);
  }

  @Public()
  @Post('validate-key')
  @ApiOperation({ summary: 'Validate a license key and return license info' })
  async validateKey(@Body() dto: ValidateKeyDto) {
    return this.licensesService.validateKey(dto.license_key);
  }
}
