import { dereferenceObjectSchema, parseRef, refItemToShape } from "../refs.js";
import { isObjectSchema } from "../types/index.js";
import { findSchemaAtPath } from "./find-shape-at-path.js";
export function getArgs(prop) {
    return '@args' in prop ? prop['@args'] : 'args' in prop ? prop.args : undefined;
}
export function getArgsSchema(projectSchema, args) {
    if (typeof args === 'object') {
        return dereferenceObjectSchema(projectSchema, args);
    }
    const ref = parseRef(projectSchema, args);
    const shapeSchema = refItemToShape(projectSchema, ref)?.schema;
    if (shapeSchema && isObjectSchema(shapeSchema)) {
        return shapeSchema;
    }
}
export function hasArg(projectSchema, prop, argPath) {
    const args = getArgs(prop);
    if (!args) {
        return false;
    }
    const schema = getArgsSchema(projectSchema, args);
    const pathArray = Array.isArray(argPath) ? argPath : argPath.split('.');
    return Boolean(schema && findSchemaAtPath(projectSchema, schema, pathArray));
}
