import { migrateTo } from "../migration/index.js";
import { isProjectSchemaJSONV1_0_0, isProjectSchemaJSONV3_0_0, isProjectSchemaJSONV3_1_0, isProjectSchemaJSONV3_2_0, isProjectSchemaJSONV3_3_0, isProjectSchemaJSONV3_4_0, isProjectSchemaJSONV3_5_0, isProjectSchemaJSONV3_5_1, isProjectSchemaJSONV3_6_0, isProjectSchemaJSONV3_7_0, isProjectSchemaJSONV3_8_0, isProjectSchemaJSONV3_9_0, isProjectSchemaJSONV3_10_0, isProjectSchemaJSONV3_11_0, isProjectSchemaJSONV3_12_0, isProjectSchemaJSONV3_12_1, isProjectSchemaJSONV3_12_2, isProjectSchemaJSONV3_12_3, isProjectSchemaJSONV3_13_0, isProjectSchemaJSONV3_14_0, isProjectSchemaJSONV3_15_0, isProjectSchemaJSONV3_16_0, isProjectSchemaJSONV3_17_0, isProjectSchemaJSONV3_17_1, isProjectSchemaJSONV3_18_0, isProjectSchemaJSONV3_18_1, isProjectSchemaJSONV3_18_2, isProjectSchemaJSONV3_19_0, isProjectSchemaJSONV3_20_0, isProjectSchemaJSONV3_21_0, isProjectSchemaJSONV3_22_0, isProjectSchemaJSONV3_23_0, isProjectSchemaJSONV3_24_0, isProjectSchemaJSONV3_25_0, isProjectSchemaJSONV3_26_0, isProjectSchemaJSONV3_27_0, isProjectSchemaJSONV3_28_0, isProjectSchemaJSONV3_29_0, isProjectSchemaJSONV3_30_0, isProjectSchemaJSONV3_31_0, isProjectSchemaJSONV3_32_0, isProjectSchemaJSONV3_33_0, isProjectSchemaJSONV3_34_0, isProjectSchemaJSONV3_35_0, isProjectSchemaJSONV3_36_0, isProjectSchemaJSONV3_37_0, isProjectSchemaJSONV3_38_0, isProjectSchemaJSONV3_39_0, isProjectSchemaJSONV3_40_0, isProjectSchemaJSONV3_41_0, isProjectSchemaJSONV3_42_0, isProjectSchemaJSONV3_43_0, isProjectSchemaJSONV3_44_0, isProjectSchemaJSONV3_45_0, isProjectSchemaJSONV3_46_0, isProjectSchemaJSONV3_47_0, isProjectSchemaJSONV3_48_0, isProjectSchemaJSONV3_49_0, isProjectSchemaJSONV3_50_0, isProjectSchemaJSONV3_51_0, isProjectSchemaJSONV3_52_0, isProjectSchemaJSONV3_53_0, isProjectSchemaJSONV3_54_0, isProjectSchemaJSONV3_55_0, isProjectSchemaJSONV3_56_0, isProjectSchemaJSONV3_57_0, isProjectSchemaJSONV3_58_0, isProjectSchemaJSONV4_0_0, isLatestProjectSchemaJSON } from "./index.js";
export async function migrateToLatestProjectSchema(context, projectSchema) {
    if (isLatestProjectSchemaJSON(projectSchema)) {
        return projectSchema;
    }
    if (isProjectSchemaJSONV1_0_0(projectSchema)) {
        projectSchema = await migrateTo['v3.0.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_0_0(projectSchema)) {
        projectSchema = await migrateTo['v3.1.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_1_0(projectSchema)) {
        projectSchema = await migrateTo['v3.2.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_2_0(projectSchema)) {
        projectSchema = await migrateTo['v3.3.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_3_0(projectSchema)) {
        projectSchema = await migrateTo['v3.4.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_4_0(projectSchema)) {
        projectSchema = await migrateTo['v3.5.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_5_0(projectSchema)) {
        projectSchema = await migrateTo['v3.5.1'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_5_1(projectSchema)) {
        projectSchema = await migrateTo['v3.6.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_6_0(projectSchema)) {
        projectSchema = await migrateTo['v3.7.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_7_0(projectSchema)) {
        projectSchema = await migrateTo['v3.8.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_8_0(projectSchema)) {
        projectSchema = await migrateTo['v3.9.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_9_0(projectSchema)) {
        projectSchema = await migrateTo['v3.10.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_10_0(projectSchema)) {
        projectSchema = await migrateTo['v3.11.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_11_0(projectSchema)) {
        projectSchema = await migrateTo['v3.12.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_12_0(projectSchema)) {
        projectSchema = await migrateTo['v3.12.1'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_12_1(projectSchema)) {
        projectSchema = await migrateTo['v3.12.2'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_12_2(projectSchema)) {
        projectSchema = await migrateTo['v3.12.3'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_12_3(projectSchema)) {
        projectSchema = await migrateTo['v3.13.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_13_0(projectSchema)) {
        projectSchema = await migrateTo['v3.14.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_14_0(projectSchema)) {
        projectSchema = await migrateTo['v3.15.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_15_0(projectSchema)) {
        projectSchema = await migrateTo['v3.16.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_16_0(projectSchema)) {
        projectSchema = await migrateTo['v3.17.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_17_0(projectSchema)) {
        projectSchema = await migrateTo['v3.17.1'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_17_1(projectSchema)) {
        projectSchema = await migrateTo['v3.18.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_18_0(projectSchema)) {
        projectSchema = await migrateTo['v3.18.1'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_18_1(projectSchema)) {
        projectSchema = await migrateTo['v3.18.2'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_18_2(projectSchema)) {
        projectSchema = await migrateTo['v3.19.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_19_0(projectSchema)) {
        projectSchema = await migrateTo['v3.20.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_20_0(projectSchema)) {
        projectSchema = await migrateTo['v3.21.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_21_0(projectSchema)) {
        projectSchema = await migrateTo['v3.22.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_22_0(projectSchema)) {
        projectSchema = await migrateTo['v3.23.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_23_0(projectSchema)) {
        projectSchema = await migrateTo['v3.24.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_24_0(projectSchema)) {
        projectSchema = await migrateTo['v3.25.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_25_0(projectSchema)) {
        projectSchema = await migrateTo['v3.26.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_26_0(projectSchema)) {
        projectSchema = await migrateTo['v3.27.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_27_0(projectSchema)) {
        projectSchema = await migrateTo['v3.28.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_28_0(projectSchema)) {
        projectSchema = await migrateTo['v3.29.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_29_0(projectSchema)) {
        projectSchema = await migrateTo['v3.30.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_30_0(projectSchema)) {
        projectSchema = await migrateTo['v3.31.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_31_0(projectSchema)) {
        projectSchema = await migrateTo['v3.32.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_32_0(projectSchema)) {
        projectSchema = await migrateTo['v3.33.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_33_0(projectSchema)) {
        projectSchema = await migrateTo['v3.34.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_34_0(projectSchema)) {
        projectSchema = await migrateTo['v3.35.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_35_0(projectSchema)) {
        projectSchema = await migrateTo['v3.36.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_36_0(projectSchema)) {
        projectSchema = await migrateTo['v3.37.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_37_0(projectSchema)) {
        projectSchema = await migrateTo['v3.38.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_38_0(projectSchema)) {
        projectSchema = await migrateTo['v3.39.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_39_0(projectSchema)) {
        projectSchema = await migrateTo['v3.40.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_40_0(projectSchema)) {
        projectSchema = await migrateTo['v3.41.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_41_0(projectSchema)) {
        projectSchema = await migrateTo['v3.42.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_42_0(projectSchema)) {
        projectSchema = await migrateTo['v3.43.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_43_0(projectSchema)) {
        projectSchema = await migrateTo['v3.44.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_44_0(projectSchema)) {
        projectSchema = await migrateTo['v3.45.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_45_0(projectSchema)) {
        projectSchema = await migrateTo['v3.46.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_46_0(projectSchema)) {
        projectSchema = await migrateTo['v3.47.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_47_0(projectSchema)) {
        projectSchema = await migrateTo['v3.48.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_48_0(projectSchema)) {
        projectSchema = await migrateTo['v3.49.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_49_0(projectSchema)) {
        projectSchema = await migrateTo['v3.50.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_50_0(projectSchema)) {
        projectSchema = await migrateTo['v3.51.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_51_0(projectSchema)) {
        projectSchema = await migrateTo['v3.52.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_52_0(projectSchema)) {
        projectSchema = await migrateTo['v3.53.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_53_0(projectSchema)) {
        projectSchema = await migrateTo['v3.54.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_54_0(projectSchema)) {
        projectSchema = await migrateTo['v3.55.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_55_0(projectSchema)) {
        projectSchema = await migrateTo['v3.56.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_56_0(projectSchema)) {
        projectSchema = await migrateTo['v3.57.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_57_0(projectSchema)) {
        projectSchema = await migrateTo['v3.58.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV3_58_0(projectSchema)) {
        projectSchema = await migrateTo['v3.59.0'](context, projectSchema);
    }
    if (isProjectSchemaJSONV4_0_0(projectSchema)) {
        throw new Error('You are using an unreleased schema version. Migration is not possible');
    }
    return projectSchema;
}
export async function ensureLatest(context, schema) {
    if (!schema || isLatestProjectSchemaJSON(schema)) {
        return schema;
    }
    return migrateToLatestProjectSchema(context, schema);
}
