import { Controller, Get, Query } from '@nestjs/common';
import { SearchCustomerDTO } from '@studio-m/app-types';
import { CustomerRepo } from '../../repos/customer.repo';
import { CustomerMapper } from '../../mappers/customer.mapper';

@Controller('customers')
export class SearchCustomers {
  constructor(private customerRepo: CustomerRepo) {}

  @Get()
  async execute(@Query() body: SearchCustomerDTO) {
    const customers = await this.customerRepo.search(body);

    return {
      items: customers.map((customer) => CustomerMapper.toDTO(customer)),
    };
  }
}
