import { Inject } from '@nestjs/common';
import { type IQueryHandler, QueryHandler } from '@nestjs/cqrs';
import {
  PROJECT_REPOSITORY,
  type IProjectRepository,
  type PaginatedResult,
  type ProjectListItem,
} from '../../../domain/repositories/project-development.repository';
import { ListProjectsQuery } from './list-projects.query';

@QueryHandler(ListProjectsQuery)
export class ListProjectsHandler implements IQueryHandler<ListProjectsQuery> {
  constructor(
    @Inject(PROJECT_REPOSITORY)
    private readonly repo: IProjectRepository,
  ) {}

  async execute(query: ListProjectsQuery): Promise<PaginatedResult<ProjectListItem>> {
    return this.repo.search({
      query: query.query,
      status: query.status,
      city: query.city,
      district: query.district,
      developer: query.developer,
      isVerified: query.isVerified,
      ownerId: query.ownerId,
      page: query.page,
      limit: query.limit,
    });
  }
}
