import { UnreachableCaseError } from "ts-essentials";
import { FernRegistry } from "../../../client/generated";
import { BaseOpenApiV3_1ConverterNode, } from "../../BaseOpenApiV3_1Converter.node";
import { SUPPORTED_X_FERN_AVAILABILITY_VALUES, } from "../../types/format.types";
import { resolveSchemaReference } from "../../utils/3.1/resolveSchemaReference";
import { extendType } from "../../utils/extendType";
import { X_FERN_AVAILABILITY } from "./fernExtension.consts";
export class AvailabilityConverterNode extends BaseOpenApiV3_1ConverterNode {
    availability;
    constructor(args) {
        super(args);
        this.safeParse();
    }
    parse() {
        const input = resolveSchemaReference(this.input, this.context.document);
        if (input?.deprecated) {
            this.availability = "deprecated";
        }
        else {
            const maybeAvailability = extendType(this.input)[X_FERN_AVAILABILITY];
            if (maybeAvailability != null) {
                if (SUPPORTED_X_FERN_AVAILABILITY_VALUES.includes(maybeAvailability)) {
                    this.availability = maybeAvailability;
                }
                else {
                    this.context.errors.warning({
                        message: `Expected one of: ${SUPPORTED_X_FERN_AVAILABILITY_VALUES.join(", ")}. Received: ${maybeAvailability}`,
                        path: this.accessPath,
                    });
                    this.availability = undefined;
                }
            }
        }
    }
    convert() {
        switch (this.availability) {
            case "beta":
            case "pre-release":
                return FernRegistry.Availability.Beta;
            case "in-development":
                return FernRegistry.Availability.InDevelopment;
            case "generally-available":
                return FernRegistry.Availability.GenerallyAvailable;
            case "deprecated":
                return FernRegistry.Availability.Deprecated;
            case undefined:
                return undefined;
            default:
                new UnreachableCaseError(this.availability);
                return undefined;
        }
    }
}
