2025-05-02 21:43:51 +00:00
|
|
|
import { Slug } from "@/core/common/domain";
|
|
|
|
|
import { Collection } from "@/core/common/helpers";
|
2025-02-25 15:25:30 +00:00
|
|
|
import { Tax } from "./tax";
|
|
|
|
|
|
|
|
|
|
export class TaxCollection extends Collection<Tax> {
|
|
|
|
|
constructor(items: Tax[] = []) {
|
|
|
|
|
super(items);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
|
|
Agrega un impuesto a la colección garantizando que el slug sea único. */
|
|
|
|
|
add(tax: Tax): void {
|
|
|
|
|
if (this.exists(tax.slug)) {
|
|
|
|
|
throw new Error(`(El impuesto con slug "${tax.slug.toString()}" ya existe.`);
|
|
|
|
|
}
|
|
|
|
|
this.add(tax);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
|
|
Verifica si un slug ya existe en la colección. */
|
|
|
|
|
exists(slug: Slug): boolean {
|
|
|
|
|
return this.some((tax) => tax.slug.equals(slug));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
|
|
Encuentra un impuesto por su slug. */
|
|
|
|
|
findBySlug(slug: Slug): Tax | undefined {
|
|
|
|
|
return this.find((tax) => tax.slug.equals(slug));
|
|
|
|
|
}
|
|
|
|
|
}
|