import { z } from "zod/v3";
export const RHEI_PREMIUM_FEATURES = [
    "premium_context_rerank",
    "premium_graph_expand",
    "premium_service_enrichment",
    "premium_drift_signals",
];
export const RHEI_PREMIUM_MODE_VALUES = ["off", "auto", "required"];
export const RHEI_SOURCE_UPLOAD_MODE_VALUES = ["never", "metadata_only", "selected_slices"];
export const RheiPremiumFeatureV1Schema = z.enum(RHEI_PREMIUM_FEATURES);
export const RheiPremiumModeV1Schema = z.enum(RHEI_PREMIUM_MODE_VALUES);
export const RheiSourceUploadModeV1Schema = z.enum(RHEI_SOURCE_UPLOAD_MODE_VALUES);
export const RheiLicenseStatusV1Schema = z.object({
    kind: z.literal("RheiLicenseStatusV1"),
    schemaVersion: z.literal(1),
    status: z.enum([
        "anonymous",
        "authenticated_free",
        "entitled",
        "not_entitled",
        "expired",
        "rate_limited",
        "unreachable",
    ]),
    tenantId: z.string().optional(),
    accountId: z.string().optional(),
    enabledFeatures: z.array(RheiPremiumFeatureV1Schema),
    expiresAt: z.string().optional(),
    checkedAt: z.string(),
    serverTraceId: z.string().optional(),
});
export const RheiPremiumTrialStartResponseV1Schema = z.object({
    kind: z.literal("RheiPremiumTrialStartResponseV1"),
    schemaVersion: z.literal(1),
    status: z.enum(["ok", "not_authenticated", "unavailable"]),
    created: z.boolean().optional(),
    expiresAt: z.string().optional(),
    license: RheiLicenseStatusV1Schema.optional(),
    serverTraceId: z.string().optional(),
    advisoryOnly: z.literal(true).optional(),
    warnings: z.array(z.string()).optional(),
});
export const RheiPremiumContextPlanRequestV1Schema = z.object({
    kind: z.literal("RheiPremiumContextPlanRequestV1"),
    schemaVersion: z.literal(1),
    feature: RheiPremiumFeatureV1Schema,
    client: z.object({
        packageName: z.enum(["@rhei-team/rhei", "@rhei-team/mcp-server", "@rhei/mcp-server"]),
        packageVersion: z.string(),
        commandRunner: z.enum(["npm", "npx", "bunx", "pnpm", "pnpm_dlx", "local", "unknown"]).optional(),
        capabilities: z.array(z.string()),
    }),
    repo: z.object({
        repoFingerprint: z.string(),
        sourceEpochHash: z.string().optional(),
        indexFreshness: z.string().optional(),
        localSqlSchemaVersion: z.number().optional(),
    }),
    privacy: z.object({
        sourceUpload: RheiSourceUploadModeV1Schema,
        redactionPolicy: z.enum(["default_local", "none", "custom"]),
        maxBytes: z.number().nonnegative(),
    }),
    goal: z.object({
        text: z.string().optional(),
        responseType: z.string().optional(),
        targetAgent: z.string().optional(),
        tokenBudget: z.number().positive().optional(),
    }),
    localCandidates: z.array(z.object({
        path: z.string(),
        contentHash: z.string().optional(),
        language: z.string().optional(),
        spans: z.array(z.object({
            startLine: z.number().int().positive(),
            endLine: z.number().int().positive(),
            text: z.string().optional(),
        })).optional(),
        localReasonCodes: z.array(z.string()).optional(),
    })),
});
export const RheiPremiumContextPlanResponseV1Schema = z.object({
    kind: z.literal("RheiPremiumContextPlanResponseV1"),
    schemaVersion: z.literal(1),
    status: z.enum(["ok", "degraded", "not_authenticated", "not_entitled", "rate_limited", "unavailable"]),
    license: RheiLicenseStatusV1Schema,
    serverTraceId: z.string(),
    advisoryOnly: z.literal(true),
    rankedRefs: z.array(z.object({
        path: z.string(),
        rank: z.number(),
        reasonCodes: z.array(z.string()),
        evidenceRefs: z.array(z.string()).optional(),
    })).optional(),
    graphEvidence: z.unknown().optional(),
    warnings: z.array(z.string()).optional(),
});