import { Inject } from '@nestjs/common';
import { type IQueryHandler, QueryHandler } from '@nestjs/cqrs';
import {
  INDUSTRIAL_LISTING_REPOSITORY,
  type IIndustrialListingRepository,
  type IndustrialListingDetailData,
} from '../../../domain/repositories/industrial-listing.repository';
import { GetIndustrialListingQuery } from './get-industrial-listing.query';

@QueryHandler(GetIndustrialListingQuery)
export class GetIndustrialListingHandler implements IQueryHandler<GetIndustrialListingQuery> {
  constructor(
    @Inject(INDUSTRIAL_LISTING_REPOSITORY)
    private readonly repo: IIndustrialListingRepository,
  ) {}

  async execute(query: GetIndustrialListingQuery): Promise<IndustrialListingDetailData | null> {
    return this.repo.findDetailById(query.id);
  }
}
