import { Controller, Get, Param, Query } from '@nestjs/common';
import { FilterSeasonPeriodDto } from './dto/filter-season-period.dto';
import { Pagination } from 'src/core/response';
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
import { SeasonPeriodEntity } from '../domain/entities/season-period.entity';
import { SeasonPeriodReadOrchestrator } from '../domain/usecases/season-period-read.orchestrator';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
import { Public } from 'src/core/guards';
import { ItemRateEntity } from 'src/modules/item-related/item-rate/domain/entities/item-rate.entity';
import { FilterItemRateDto } from 'src/modules/item-related/item-rate/infrastructure/dto/filter-item-rate.dto';
import { FilterCurrentSeasonDto } from './dto/filter-current-season.dto';

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

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

  @Public(true)
  @Get('current-period')
  async currentPeriod(
    @Query() params: FilterCurrentSeasonDto,
  ): Promise<SeasonPeriodEntity> {
    return await this.orchestrator.currentPeriod(params);
  }

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

  @Get(':id/items')
  @Pagination()
  async indexItem(
    @Query() params: FilterItemRateDto,
    @Param('id') id: string,
  ): Promise<PaginationResponse<ItemRateEntity>> {
    params.season_period_ids = [id];
    return await this.orchestrator.indexItem(params);
  }
}
