import { CompositeSpecification } from "@repo/rdx-ddd";
import { I
{
  pascalCase;
  name;
}
Repository;
} from "../../domain/repositories"

export class {
  {
  pascalCase;
  name;
}
}UniqueNameSpecification extends CompositeSpecification<string>
{
  constructor(
    private readonly repo: I{{pascalCase name}}Repository,
    private readonly transaction?: unknown
  )
  super();

  async;
  isSatisfiedBy(name: string)
  : Promise<boolean>
  {
    const criteria = { filters: { name } };
    const resultOrError = await this.repo.findByCriteria(criteria as any, this.transaction);
    if (resultOrError.isFailure) throw resultOrError.error;
    return resultOrError.data.total() === 0;
  }
}
