import { Controller, Get, Query, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
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 { SearchQueryDto, SearchSuggestionsQueryDto } from './dto/search-query.dto';
import { SearchService } from './search.service';

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

  @Get()
  async globalSearch(@CurrentUser() user: JwtPayload, @Query() query: SearchQueryDto) {
    return this.searchService.globalSearch(user.sub, query);
  }

  @Get('users')
  async searchUsers(@CurrentUser() user: JwtPayload, @Query() query: SearchQueryDto) {
    return this.searchService.searchUsers(user.sub, query);
  }

  @Get('posts')
  async searchPosts(@CurrentUser() user: JwtPayload, @Query() query: SearchQueryDto) {
    return this.searchService.searchPosts(user.sub, query);
  }

  @Get('hashtags')
  async searchHashtags(@CurrentUser() user: JwtPayload, @Query() query: SearchQueryDto) {
    return this.searchService.searchHashtags(user.sub, query);
  }

  @Get('suggestions')
  async suggestions(@CurrentUser() user: JwtPayload, @Query() query: SearchSuggestionsQueryDto) {
    return this.searchService.getSuggestions(user.sub, query);
  }
}
