"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HexRelease = void 0;
const zod_1 = require("zod");
const schema_utils_1 = require("../../../util/schema-utils");
exports.HexRelease = zod_1.z
    .object({
    html_url: zod_1.z.string().optional(),
    meta: zod_1.z
        .object({
        links: zod_1.z.object({
            Github: zod_1.z.string(),
        }),
    })
        .nullable()
        .catch(null),
    releases: (0, schema_utils_1.LooseArray)(zod_1.z.object({
        version: zod_1.z.string(),
        inserted_at: zod_1.z.string().optional(),
    })).refine((releases) => releases.length > 0, 'No releases found'),
})
    .transform((hexResponse) => {
    const releases = hexResponse.releases.map(({ version, inserted_at: releaseTimestamp }) => {
        const release = { version };
        if (releaseTimestamp) {
            release.releaseTimestamp = releaseTimestamp;
        }
        return release;
    });
    const releaseResult = { releases };
    if (hexResponse.html_url) {
        releaseResult.homepage = hexResponse.html_url;
    }
    if (hexResponse.meta?.links?.Github) {
        releaseResult.sourceUrl = hexResponse.meta.links.Github;
    }
    return releaseResult;
});
//# sourceMappingURL=schema.js.map