import { import_process_fail } from "./import_process_fail";

export class import_log {
    #log;
 
    constructor() {
        this.#log = new Array();
    }

    #append(target) {
        this.#log.push(target);
    }

    #error_dump(error) {
        return (
            "Error: "
            + new String(error) + "."
        );
    }

    #product_dump(product) {
        return (
            "Product: "
            + "barcode: \"" + product.barcode + "\", " 
            + "title: \"" + product.title + "\"."
        );
    }

    fail(target) {
        this.#append(
            "Fail when processing item. "
            + this.#product_dump(target.product) + " "
            + this.#error_dump(target.error)
        );
    }

    skip(target) {
        this.#append(
            "Skipping not ready item. "
            + this.#product_dump(target.product) + " "
            + this.#error_dump(target.error)
        );
    }

    get length() {
        return this.#log.length;
    }

    content() {
        return this.#log.join("\n");
    }
}