import { reservation } from "./reservation.js";

export class reservation_factory {
    #target;

    constructor() {
        this.#target = new reservation();
    }

    phone_number(target) {
        target = target.trim().replaceAll("-", "");

        if (target.length === 0) {
            target = null;
        }

        this.#target.phone_number = target;
        return this;
    }

    email(target) {
        target = target.trim();

        if (target.length === 0) {
            target = null;
        }

        this.#target.email = target;
        return this;
    }

    product(target) {
        this.#target.product_barcode = target.barcode;
        return this;
    }

    result() {
        if (this.#target.ready) {
            return this.#target;
        }

        throw new Error("Target reservation is not ready yet.");
    }
}
