"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Lockfile = exports.PoetrySchemaToml = exports.PoetrySchema = exports.PoetrySectionSchema = exports.PoetryGroupRecord = exports.PoetryDependencyRecord = void 0;
const zod_1 = require("zod");
const schema_utils_1 = require("../../../util/schema-utils");
const PoetryDependencySchema = zod_1.z.object({
    path: zod_1.z.string().optional(),
    git: zod_1.z.string().optional(),
    tag: zod_1.z.string().optional(),
    version: zod_1.z.string().optional(),
});
exports.PoetryDependencyRecord = (0, schema_utils_1.LooseRecord)(zod_1.z.string(), zod_1.z.union([PoetryDependencySchema, zod_1.z.array(PoetryDependencySchema), zod_1.z.string()]));
exports.PoetryGroupRecord = (0, schema_utils_1.LooseRecord)(zod_1.z.string(), zod_1.z.object({
    dependencies: exports.PoetryDependencyRecord.optional(),
}));
exports.PoetrySectionSchema = zod_1.z.object({
    dependencies: exports.PoetryDependencyRecord.optional(),
    'dev-dependencies': exports.PoetryDependencyRecord.optional(),
    extras: exports.PoetryDependencyRecord.optional(),
    group: exports.PoetryGroupRecord.optional(),
    source: zod_1.z
        .array(zod_1.z.object({ name: zod_1.z.string(), url: zod_1.z.string().optional() }))
        .optional(),
});
exports.PoetrySchema = zod_1.z.object({
    tool: zod_1.z
        .object({
        poetry: exports.PoetrySectionSchema.optional(),
    })
        .optional(),
    'build-system': zod_1.z
        .object({
        requires: zod_1.z.array(zod_1.z.string()),
        'build-backend': zod_1.z.string().optional(),
    })
        .optional(),
});
exports.PoetrySchemaToml = schema_utils_1.Toml.pipe(exports.PoetrySchema);
const poetryConstraint = {
    '1.0': '<1.1.0',
    '1.1': '<1.3.0',
    '2.0': '>=1.3.0',
};
exports.Lockfile = schema_utils_1.Toml.pipe(zod_1.z.object({
    package: (0, schema_utils_1.LooseArray)(zod_1.z
        .object({
        name: zod_1.z.string(),
        version: zod_1.z.string(),
    })
        .transform(({ name, version }) => [name, version]))
        .transform((entries) => Object.fromEntries(entries))
        .catch({}),
    metadata: zod_1.z
        .object({
        'lock-version': zod_1.z
            .string()
            .transform((lockVersion) => poetryConstraint[lockVersion])
            .optional()
            .catch(undefined),
        'python-versions': zod_1.z.string().optional().catch(undefined),
    })
        .transform(({ 'lock-version': poetryConstraint, 'python-versions': pythonVersions, }) => ({
        poetryConstraint,
        pythonVersions,
    }))
        .catch({
        poetryConstraint: undefined,
        pythonVersions: undefined,
    }),
})).transform(({ package: lock, metadata: { poetryConstraint, pythonVersions } }) => ({
    lock,
    poetryConstraint,
    pythonVersions,
}));
//# sourceMappingURL=schema.js.map