import { Controller, Get, Param, Query } from '@nestjs/common';
import { FilterNewsDto } from './dto/filter-news.dto';
import { Pagination } from 'src/core/response';
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
import { NewsEntity } from '../domain/entities/news.entity';
import { NewsReadOrchestrator } from '../domain/usecases/news-read.orchestrator';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
import { Public } from 'src/core/guards';

@ApiTags(`${MODULE_NAME.NEWS.split('-').join(' ')} - read`)
@Controller(`v1/${MODULE_NAME.NEWS}`)
@Public(false)
@ApiBearerAuth('JWT')
export class NewsReadController {
  constructor(private orchestrator: NewsReadOrchestrator) {}

  @Get()
  @Pagination()
  async index(
    @Query() params: FilterNewsDto,
  ): Promise<PaginationResponse<NewsEntity>> {
    return await this.orchestrator.index(params);
  }

  @Get(':id')
  async detail(@Param('id') id: string): Promise<NewsEntity> {
    return await this.orchestrator.detail(id);
  }
}
