export function obfuscateShortcutClientEmail(email) {
    if (!email)
        return '';
    const atIndex = email.indexOf('@');
    if (atIndex === -1)
        return '';
    return `*****${email.slice(atIndex)}`;
}
export function normalizeShortcutClientPlanType(planType) {
    if (planType === undefined)
        return '';
    if (planType === null)
        return 'free';
    const normalized = planType.trim().toLowerCase();
    if (!normalized)
        return '';
    if (normalized === 'free')
        return 'free';
    if (normalized === 'team' || normalized.includes('enterprise') || normalized.includes('team')) {
        return 'team';
    }
    if (normalized === 'pro' ||
        normalized === 'premium' ||
        normalized === 'max' ||
        normalized.includes('pro') ||
        normalized.includes('premium') ||
        normalized.includes('max')) {
        return 'pro';
    }
    return '';
}
/**
 * Mutable runtime-owned log context.
 *
 * Owns only stable correlation fields that should be inherited by emitted log rows.
 * Event-specific payloads stay outside this store.
 */
export class ShortcutClientLogContextStore {
    context = {};
    setUserId(userId) {
        this.context.user_id = userId;
    }
    clearUserId() {
        this.context.user_id = undefined;
    }
    setSessionId(sessionId) {
        this.context.session_id = sessionId;
    }
    clearSessionId() {
        this.context.session_id = undefined;
    }
    setRequestId(requestId) {
        this.context.request_id = requestId;
    }
    clearRequestId() {
        this.context.request_id = undefined;
    }
    setRunId(runId) {
        this.context.run_id = runId;
    }
    clearRunId() {
        this.context.run_id = undefined;
    }
    setFileId(fileId) {
        this.context.file_id = fileId;
    }
    clearFileId() {
        this.context.file_id = undefined;
    }
    setBuildInfo(input) {
        this.context.commit = input.commit;
        this.context.version = input.version;
    }
    setUserContext(input) {
        this.context.plan_type = normalizeShortcutClientPlanType(input.planType);
        this.context.plan_tier = input.planTier ?? 0;
        this.context.team_id = input.teamId ?? '';
        this.context.team_role = input.teamRole ?? '';
        this.context.email = obfuscateShortcutClientEmail(input.email);
    }
    clearUserContext() {
        this.context.plan_type = undefined;
        this.context.plan_tier = undefined;
        this.context.team_id = undefined;
        this.context.team_role = undefined;
        this.context.email = undefined;
    }
    getSnapshot() {
        return { ...this.context };
    }
}
//# sourceMappingURL=context.js.map