"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.authProfileStateFileSchema = exports.authProfileStateSchema = exports.authProfilesFileSchema = exports.authProfileSchema = exports.authProfileOrderSchema = exports.authProfileCreatedAtSchema = exports.codexLoginMethodSchema = exports.authProfileProviderSchema = exports.authProfileStatusSchema = exports.authProfileKindSchema = exports.authProfileIdSchema = exports.AUTH_PROFILE_STATE_VERSION = exports.AUTH_PROFILES_VERSION = void 0;
const zod_1 = require("zod");
const catalog_1 = require("../i18n/catalog");
const definitions_1 = require("./definitions");
exports.AUTH_PROFILES_VERSION = 3;
exports.AUTH_PROFILE_STATE_VERSION = 1;
exports.authProfileIdSchema = zod_1.z
    .string()
    .regex(/^auth_[0-9A-HJKMNP-TV-Z]{26}$/, (0, catalog_1.translate)(catalog_1.DEFAULT_APP_LOCALE, "auth.profile.error.invalidId"));
exports.authProfileKindSchema = zod_1.z.enum(definitions_1.AUTH_PROFILE_KIND_VALUES);
exports.authProfileStatusSchema = zod_1.z.enum([
    "ready",
    "cooldown",
    "auth_invalid",
]);
exports.authProfileProviderSchema = zod_1.z.enum(definitions_1.AUTH_PROFILE_PROVIDER_VALUES);
exports.codexLoginMethodSchema = zod_1.z.enum([
    "browser",
    "device-auth",
    "api-key",
]);
exports.authProfileCreatedAtSchema = zod_1.z.string().min(1);
exports.authProfileOrderSchema = zod_1.z.number().int().positive();
const authProfileBaseSchema = zod_1.z
    .object({
    id: exports.authProfileIdSchema,
    createdAt: exports.authProfileCreatedAtSchema,
    order: exports.authProfileOrderSchema,
})
    .strict();
const codexHomeAuthProfileSchema = authProfileBaseSchema
    .extend({
    kind: zod_1.z.literal("codex-home"),
    codexLoginMethod: exports.codexLoginMethodSchema,
    codexHomePath: zod_1.z.string().min(1),
})
    .strict();
const codexEnvVarAuthProfileSchema = authProfileBaseSchema
    .extend({
    kind: zod_1.z.literal("codex-env-var"),
    envVarName: zod_1.z.literal(definitions_1.CODEX_API_KEY_ENV_VAR_NAME),
})
    .strict();
const claudeEnvVarAuthProfileSchema = authProfileBaseSchema
    .extend({
    kind: zod_1.z.literal("claude-env-var"),
    envVarName: zod_1.z.literal(definitions_1.CLAUDE_API_KEY_ENV_VAR_NAME),
})
    .strict();
const claudeApiKeyAuthProfileSchema = authProfileBaseSchema
    .extend({
    kind: zod_1.z.literal("claude-api-key"),
})
    .strict();
const claudeCliAuthProfileSchema = authProfileBaseSchema
    .extend({
    kind: zod_1.z.literal("claude-cli"),
    claudeConfigPath: zod_1.z.string().min(1),
})
    .strict();
exports.authProfileSchema = zod_1.z.discriminatedUnion("kind", [
    codexHomeAuthProfileSchema,
    codexEnvVarAuthProfileSchema,
    claudeApiKeyAuthProfileSchema,
    claudeEnvVarAuthProfileSchema,
    claudeCliAuthProfileSchema,
]);
exports.authProfilesFileSchema = zod_1.z
    .object({
    version: zod_1.z.literal(exports.AUTH_PROFILES_VERSION),
    profiles: zod_1.z.array(exports.authProfileSchema),
})
    .strict();
exports.authProfileStateSchema = zod_1.z
    .object({
    profileId: exports.authProfileIdSchema,
    status: exports.authProfileStatusSchema,
    cooldownUntil: zod_1.z.string().min(1).nullable(),
    lastReason: zod_1.z.string().min(1).nullable(),
    updatedAt: zod_1.z.string().min(1),
})
    .strict();
exports.authProfileStateFileSchema = zod_1.z
    .object({
    version: zod_1.z.literal(exports.AUTH_PROFILE_STATE_VERSION),
    states: zod_1.z.array(exports.authProfileStateSchema),
})
    .strict();
