"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GemVersions = exports.GemMetadata = exports.MarshalledVersionInfo = void 0;
const tslib_1 = require("tslib");
const is_1 = tslib_1.__importDefault(require("@sindresorhus/is"));
const zod_1 = require("zod");
const schema_utils_1 = require("../../../util/schema-utils");
exports.MarshalledVersionInfo = (0, schema_utils_1.LooseArray)(zod_1.z
    .object({
    number: zod_1.z.string(),
})
    .transform(({ number: version }) => ({ version })))
    .transform((releases) => (releases.length === 0 ? null : { releases }))
    .nullable()
    .catch(null);
exports.GemMetadata = zod_1.z
    .object({
    name: zod_1.z.string().transform((x) => x.toLowerCase()),
    version: zod_1.z.string().nullish().catch(null),
    changelog_uri: zod_1.z.string().nullish().catch(null),
    homepage_uri: zod_1.z.string().nullish().catch(null),
    source_code_uri: zod_1.z.string().nullish().catch(null),
})
    .transform(({ name: packageName, version, changelog_uri: changelogUrl, homepage_uri: homepage, source_code_uri: sourceUrl, }) => ({
    packageName,
    latestVersion: version,
    changelogUrl,
    homepage,
    sourceUrl,
}));
exports.GemVersions = (0, schema_utils_1.LooseArray)(zod_1.z
    .object({
    number: zod_1.z.string(),
    created_at: zod_1.z.string(),
    platform: zod_1.z.string().nullable().catch(null),
    ruby_version: zod_1.z.string().nullable().catch(null),
    rubygems_version: zod_1.z.string().nullable().catch(null),
})
    .transform(({ number: version, created_at: releaseTimestamp, platform, ruby_version: rubyVersion, rubygems_version: rubygemsVersion, }) => {
    const result = { version, releaseTimestamp };
    const constraints = {};
    if (platform) {
        constraints.platform = [platform];
    }
    if (rubyVersion) {
        constraints.ruby = [rubyVersion];
    }
    if (rubygemsVersion) {
        constraints.rubygems = [rubygemsVersion];
    }
    if (!is_1.default.emptyObject(constraints)) {
        result.constraints = constraints;
    }
    return result;
}));
//# sourceMappingURL=schema.js.map