import {
  ClassSerializerInterceptor,
  Controller,
  Get,
  Param,
  Query,
  UseInterceptors,
} from '@nestjs/common';
import { FoodsService } from './foods.service';
import {
  RetrieveFoodsQueryParamsDto,
  RetrieveFoodsResponseDto,
} from './dtos/retrieve-foods.dto';
import { IsPublic } from '../../shared/decorators/auth/is-public.decorator';
import {
  ApiDefaultResponseStatus,
  ApiResponseStatuses,
} from '../../shared/decorators/swagger/api-response-statuses.decorator';
import { SingleIdParamsDto } from '../../shared/dtos/params/single-id-params.dto';
import { RetrieveFoodResponseDto } from './dtos/retrieve-food.dto';
import { ApiTags } from '@nestjs/swagger';
import { IUser, User } from '../../shared/decorators/auth/user.decorator';
import { RetrieveFrequentFoods } from './dtos/retrieve-frequent-foods.dto';

@ApiTags('Foods')
@Controller('foods')
export class FoodsController {
  constructor(private readonly _foodsService: FoodsService) {}

  @Get()
  @IsPublic()
  @ApiDefaultResponseStatus(200, RetrieveFoodsResponseDto)
  @ApiResponseStatuses(400, 502)
  @UseInterceptors(ClassSerializerInterceptor)
  async retrieveFoods(
    @Query() queryParams: RetrieveFoodsQueryParamsDto,
  ): Promise<RetrieveFoodsResponseDto> {
    return this._foodsService.retrieveFoods(queryParams);
  }

  @Get('frequent')
  @IsPublic()
  @ApiDefaultResponseStatus(200, RetrieveFrequentFoods)
  @ApiResponseStatuses(502)
  @UseInterceptors(ClassSerializerInterceptor)
  async retrieveFrequentFoods(
    @User() user?: IUser,
  ): Promise<RetrieveFrequentFoods> {
    return this._foodsService.retrieveFrequentFoods(user);
  }

  @Get(':id')
  @IsPublic()
  @ApiDefaultResponseStatus(200, RetrieveFoodResponseDto)
  @ApiResponseStatuses(400, 404, 502)
  @UseInterceptors(ClassSerializerInterceptor)
  async retrieveFood(
    @Param() params: SingleIdParamsDto,
    @User() user?: IUser,
  ): Promise<RetrieveFoodResponseDto> {
    return this._foodsService.retrieveFood(params, user);
  }
}
