import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { Throttle } from '../../common/decorators/throttle.decorator';
import { CurrentUser } from '../../common/decorators/current-user.decorator';
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
import { JwtPayload } from '../../common/interfaces/jwt-payload.interface';
import { TextToMusicDto } from './dto/text-to-music.dto';
import { MediaService } from './media.service';

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

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard)
  @Get('health')
  async mediaHealth() {
    return this.mediaService.getMediaHealth();
  }

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard)
  @Post('ai/text-to-music')
  @Throttle(6, 60_000)
  async generateMusicFromText(@CurrentUser() user: JwtPayload, @Body() dto: TextToMusicDto) {
    return this.mediaService.generateMusicFromText(user.sub, dto);
  }
}
