import { BaseOpenApiV3_1ConverterNodeWithTracking, } from "../../BaseOpenApiV3_1Converter.node";
import { maybeSingleValueToArray } from "../../utils/maybeSingleValueToArray";
import { SchemaConverterNode } from "./SchemaConverter.node";
export class ArrayConverterNode extends BaseOpenApiV3_1ConverterNodeWithTracking {
    item;
    constructor(args) {
        super(args);
        this.safeParse();
    }
    parse() {
        this.item = new SchemaConverterNode({
            input: this.input.items,
            context: this.context,
            accessPath: this.accessPath,
            pathId: "items",
            seenSchemas: this.seenSchemas,
        });
        if (this.input.items == null) {
            this.context.errors.error({
                message: "Expected 'items' property to be specified",
                path: this.accessPath,
            });
        }
    }
    convert() {
        const maybeItemShapes = maybeSingleValueToArray(this.item?.convert());
        return maybeItemShapes?.map((itemShape) => ({
            type: "alias",
            value: {
                type: "list",
                itemShape,
            },
        }));
    }
    example(exampleArgs) {
        return (this.input.example ??
            this.input.examples?.[0] ?? [this.item?.example(exampleArgs)]);
    }
}
