import {
  Controller,
  Get,
  Query,
  UseGuards,
  HttpStatus,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth, ApiQuery } from '@nestjs/swagger';
import { SearchService } from './search.service';
import { JwtAuthGuard } from '../common/guards/jwt-auth.guard';

@ApiTags('Search')
@Controller('search')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
export class SearchController {
  constructor(private readonly searchService: SearchService) {}

  @Get()
  @ApiOperation({ summary: 'Search across channels, movies, and series' })
  @ApiQuery({ name: 'q', required: true, description: 'Search query' })
  @ApiQuery({
    name: 'type',
    required: false,
    description: 'Content type filter',
    enum: ['all', 'channel', 'movie', 'series'],
  })
  async search(
    @Query('q') query: string,
    @Query('type') type: string = 'all',
  ) {
    const results = await this.searchService.search(query, type);
    return {
      data: results,
      message: 'Search completed successfully',
      statusCode: HttpStatus.OK,
    };
  }
}
