import { Controller, Get, Param, Query } from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { Public } from 'src/core/guards';
import { Pagination } from 'src/core/response';
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
import { ItemEntity } from 'src/modules/item-related/item/domain/entities/item.entity';
import { ItemReadOrchestrator } from 'src/modules/item-related/item/domain/usecases/item-read.orchestrator';
import { FilterItemDto } from 'src/modules/item-related/item/infrastructure/dto/filter-item.dto';

@ApiTags(`${MODULE_NAME.TENANT.split('-').join(' ')} item - read`)
@Controller(`v1/${MODULE_NAME.TENANT}/:tenant_id/item`)
@Public(false)
@ApiBearerAuth('JWT')
export class TenantItemReadController {
  constructor(private orchestrator: ItemReadOrchestrator) {}

  @Get()
  @Pagination()
  async index(
    @Query() params: FilterItemDto,
    @Param('tenant_id') tenant_id: string,
  ): Promise<PaginationResponse<ItemEntity>> {
    Object.assign(params, {
      tenant_ids: [tenant_id],
    });

    return await this.orchestrator.index(params);
  }

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