import {
  Controller,
  Get,
  Param,
  ParseIntPipe,
  Query,
} from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { PublicService } from './public.service';
import { PublicQueryGoodDto } from './dto/public-query-good.dto';
import { PublicTagDto } from './dto/public-tag.dto';
import { PublicTagGroupDto } from './dto/public-tag-group.dto';

@ApiTags('public')
@Controller('public')
export class PublicController {
  constructor(private readonly service: PublicService) {}

  @Get('categories')
  @ApiOperation({ summary: 'Public list of categories that have goods' })
  getCategories() {
    return this.service.getCategoriesTree();
  }

  @Get('countries')
  @ApiOperation({ summary: 'Public list of countries that have goods' })
  getCountries() {
    return this.service.getCountries();
  }

  @Get('tags')
  @ApiOperation({ summary: 'Public list of tags that have goods' })
  getTags(): Promise<PublicTagDto[]> {
    return this.service.getTags();
  }

  @Get('tag-groups')
  @ApiOperation({ summary: 'Public list of tag groups that have goods' })
  getTagGroups(): Promise<PublicTagGroupDto[]> {
    return this.service.getTagGroups();
  }

  @Get('goods')
  @ApiOperation({ summary: 'Public paginated goods with filters' })
  getGoods(@Query() query: PublicQueryGoodDto) {
    return this.service.getGoods(query);
  }

  @Get('goods/:id')
  @ApiOperation({ summary: 'Public good detail' })
  getGood(@Param('id', ParseIntPipe) id: string) {
    return this.service.getGood(BigInt(id));
  }
}
