/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */

import { DataModelPath } from "@matter/model";
import { Val } from "@matter/protocol";
import type { Supervision } from "../../supervision/Supervision.js";

/**
 * Contextual information tracked during validation.
 */
export interface ValidationLocation {
    /**
     * The path to scrutinize, used for diagnostic messages.
     */
    path: DataModelPath;

    /**
     * To validate conformance and constraints we require access to sibling
     * values.  They are passed here when validating a record.
     */
    siblings?: Val.Struct;

    /**
     * Choice conformance requires context from the parent object.  This
     * context is passed here.
     */
    choices?: Record<string, ValidationLocation.Choice>;

    /**
     * Path used to create fully-qualified name for diagnostic messages.
     */
    location?: string[];

    /**
     * Fallback resolver for cross-struct references.  When a name cannot be resolved in siblings or the ownership
     * hierarchy, the validator calls this function.
     */
    outerResolve?: (name: string) => Val;

    /**
     * Per-instance validation configuration.  When set, controls which validation phases run for the value and its
     * children.
     */
    config?: Supervision.Config;
}

export namespace ValidationLocation {
    /**
     * Details a conformance choice.  Used during conformance validation.
     */
    export interface Choice {
        count: number;
        target: number;
        orMore: boolean;
        orLess: boolean;
    }
}
