import { ExpressController, authGuard, forbidQueryFieldGuard, tenantGuard } from "@erp/core/api";
import { GetCustomerUseCase } from "../../../application";

export class GetCustomerController extends ExpressController {
  public constructor(private readonly useCase: GetCustomerUseCase) {
    super();
    // 🔐 Reutiliza guards de auth/tenant y prohíbe 'companyId' en query
    this.useGuards(authGuard(), tenantGuard(), forbidQueryFieldGuard("companyId"));
  }

  protected async executeImpl() {
    const companyId = this.getTenantId();
    if (!companyId) {
      return this.forbiddenError("Tenant ID not found");
    }
    const { customer_id } = this.req.params;

    const result = await this.useCase.execute({ customer_id, companyId });

    return result.match(
      (data) => this.ok(data),
      (err) => this.handleError(err)
    );
  }
}
