import { ExpressController, authGuard, tenantGuard, forbidQueryFieldGuard } from "@erp/core/api";
import { List{{pascalCase name}}UseCase } from "../../../application";

/**
 * Controlador de listado paginado por tenant
 */
export class List{{pascalCase name}}Controller extends ExpressController {
  public constructor(private readonly useCase: List{{pascalCase name}}UseCase) {
    super();
    this.useGuards(authGuard(), tenantGuard(), forbidQueryFieldGuard("companyId"));
  }

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

    // TODO: mapear query → criteria/pagination
    const criteria = this.req.query ?? {};
    const pagination = undefined;

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

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