"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EndoflifeHttpResponseScheme = void 0;
const luxon_1 = require("luxon");
const zod_1 = require("zod");
const EndoflifeDateVersionScheme = zod_1.z
    .object({
    cycle: zod_1.z.string(),
    latest: zod_1.z.optional(zod_1.z.string()),
    releaseDate: zod_1.z.optional(zod_1.z.string()),
    eol: zod_1.z.optional(zod_1.z.union([zod_1.z.string(), zod_1.z.boolean()])),
    discontinued: zod_1.z.optional(zod_1.z.union([zod_1.z.string(), zod_1.z.boolean()])),
})
    .transform(({ cycle, latest, releaseDate, eol, discontinued }) => {
    let isDeprecated = false;
    // If "eol" date or "discontinued" date has passed or any of the values is explicitly true, set to deprecated
    // "support" is not checked because support periods sometimes end before the EOL.
    if (eol === true ||
        discontinued === true ||
        (typeof eol === 'string' &&
            luxon_1.DateTime.fromISO(eol, { zone: 'utc' }) <= luxon_1.DateTime.now().toUTC()) ||
        (typeof discontinued === 'string' &&
            luxon_1.DateTime.fromISO(discontinued, { zone: 'utc' }) <=
                luxon_1.DateTime.now().toUTC())) {
        isDeprecated = true;
    }
    let version = cycle;
    if (latest !== undefined) {
        version = latest;
    }
    return {
        version,
        releaseTimestamp: releaseDate,
        isDeprecated,
    };
});
exports.EndoflifeHttpResponseScheme = zod_1.z.array(EndoflifeDateVersionScheme);
//# sourceMappingURL=schema.js.map