import { Matcher } from "../Matcher.js";
import { NullDescription } from "../NullDescription.js";
import { BaseMatcher } from "../BaseMatcher.js";

export class AnyOf extends BaseMatcher {
    /**
     * @type {Matcher[]}
     */
    #matchers;

    /**
     *
     * @param {Matcher[]} matchers
     */
    constructor(matchers) {
        super();

        this.#matchers = matchers;
    }

    matches(item, mismatch_description) {
        for (const matcher of this.#matchers) {
            if (matcher.matches(item, NullDescription.INSTANCE)) {
                return true;
            }
        }

        return false;
    }

    describeTo(description) {
        description.appendList("(", " or ", ")", this.#matchers);
    }
}
