import { Controller, Post, Body, HttpStatus, Res } from '@nestjs/common';
import { ApiTags, ApiResponse, ApiOperation } from '@nestjs/swagger';
import { Response } from 'express';
import { MediaService } from './MediaService';
import type { RequestAvatarGenerationInputDTO } from './dtos/RequestAvatarGenerationInputDTO';
import type { RequestAvatarGenerationOutputDTO } from './dtos/RequestAvatarGenerationOutputDTO';

type RequestAvatarGenerationInput = RequestAvatarGenerationInputDTO;
type RequestAvatarGenerationOutput = RequestAvatarGenerationOutputDTO;

@ApiTags('media')
@Controller('media')
export class MediaController {
  constructor(private readonly mediaService: MediaService) {}

  @Post('avatar/generate')
  @ApiOperation({ summary: 'Request avatar generation' })
  @ApiResponse({ status: 201, description: 'Avatar generation request submitted', type: RequestAvatarGenerationOutput })
  async requestAvatarGeneration(
    @Body() input: RequestAvatarGenerationInput,
    @Res() res: Response,
  ): Promise<void> {
    const result = await this.mediaService.requestAvatarGeneration(input);
    if (result.success) {
      res.status(HttpStatus.CREATED).json(result);
    } else {
      res.status(HttpStatus.BAD_REQUEST).json(result);
    }
  }
}
