"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.trackedProjectRefSchema = exports.ticketTrackerProjectRefSchema = exports.repositoryHostProjectRefSchema = exports.ticketTrackerKindSchema = exports.repositoryHostKindSchema = void 0;
exports.toTrackedProjectRef = toTrackedProjectRef;
exports.serializeTrackedProjectKey = serializeTrackedProjectKey;
exports.formatTrackedProjectRef = formatTrackedProjectRef;
const zod_1 = require("zod");
const catalog_1 = require("../i18n/catalog");
const provider_kinds_1 = require("./provider-kinds");
exports.repositoryHostKindSchema = zod_1.z.enum(provider_kinds_1.REPOSITORY_HOST_KIND_VALUES);
exports.ticketTrackerKindSchema = zod_1.z.enum(provider_kinds_1.TICKET_TRACKER_KIND_VALUES);
exports.repositoryHostProjectRefSchema = zod_1.z.object({
    kind: exports.repositoryHostKindSchema,
    projectRef: zod_1.z.string().min(1),
});
exports.ticketTrackerProjectRefSchema = zod_1.z.object({
    kind: exports.ticketTrackerKindSchema,
    projectRef: zod_1.z.string().min(1),
});
exports.trackedProjectRefSchema = zod_1.z.object({
    repositoryHost: exports.repositoryHostProjectRefSchema,
    ticketTracker: exports.ticketTrackerProjectRefSchema,
});
function toTrackedProjectRef(input) {
    return {
        repositoryHost: {
            kind: input.repositoryHost.kind,
            projectRef: input.repositoryHost.projectRef,
        },
        ticketTracker: {
            kind: input.ticketTracker.kind,
            projectRef: input.ticketTracker.projectRef,
        },
    };
}
function serializeTrackedProjectKey(ref) {
    return JSON.stringify([
        ref.repositoryHost.kind,
        ref.repositoryHost.projectRef,
        ref.ticketTracker.kind,
        ref.ticketTracker.projectRef,
    ]);
}
function formatTrackedProjectRef(ref, locale = catalog_1.DEFAULT_APP_LOCALE) {
    return [
        (0, catalog_1.translate)(locale, "trackedProject.repositoryHost", {
            kind: ref.repositoryHost.kind,
            projectRef: ref.repositoryHost.projectRef,
        }),
        (0, catalog_1.translate)(locale, "trackedProject.ticketTracker", {
            kind: ref.ticketTracker.kind,
            projectRef: ref.ticketTracker.projectRef,
        }),
    ].join(" / ");
}
