/**
 * src/autonomy/types.ts
 *
 * Autonomy layer — what makes Muassis an SMB employee instead of a chatbot.
 * Five concepts:
 *   • Goal       — KPI the agent is driving toward (sales, follow-ups, etc.)
 *   • Journal    — append-only log of every autonomous action with outcome
 *   • Policy     — bounded-write rule: "auto-act under SAR X for tool Y"
 *   • Identity   — persistent facts the agent knows about its business
 *   • Escalation — surfaced decision with brain's recommendation + counterargument
 */
import { z } from 'zod';
export const goalSchema = z.object({
    id: z.string(),
    tenant_id: z.string(),
    title: z.string().min(1).max(200),
    description: z.string().nullable().optional(),
    category: z.enum([
        'sales', 'leads', 'finance', 'compliance', 'marketing',
        'operations', 'customer-success', 'general',
    ]).default('general'),
    target_value: z.number().nullable().optional(),
    current_value: z.number().default(0),
    unit: z.string().nullable().optional(),
    deadline: z.string().nullable().optional(),
    status: z.enum(['active', 'achieved', 'missed', 'archived']).default('active'),
    priority: z.number().int().min(1).max(5).default(3),
    metadata: z.record(z.string(), z.unknown()).default({}),
    created_at: z.string(),
    updated_at: z.string(),
});
export const journalEntrySchema = z.object({
    id: z.string(),
    tenant_id: z.string(),
    kind: z.string(),
    actor: z.string().default('muassis'),
    action: z.string(),
    target: z.string().nullable().optional(),
    outcome: z.enum(['success', 'failure', 'pending', 'escalated', 'declined']).default('success'),
    reason: z.string().nullable().optional(),
    metadata: z.record(z.string(), z.unknown()).default({}),
    related_goal_id: z.string().nullable().optional(),
    cost_usd: z.number().default(0),
    created_at: z.string(),
});
export const policyModeSchema = z.enum(['auto', 'ask', 'never']);
export const policySchema = z.object({
    id: z.string(),
    tenant_id: z.string(),
    policy_key: z.string(),
    description: z.string().nullable().optional(),
    mode: policyModeSchema.default('auto'),
    threshold_amount: z.number().nullable().optional(),
    threshold_currency: z.string().default('SAR'),
    conditions: z.record(z.string(), z.unknown()).default({}),
    enabled: z.boolean().default(true),
    created_at: z.string(),
    updated_at: z.string(),
});
export const identityFactSchema = z.object({
    id: z.string(),
    tenant_id: z.string(),
    fact_key: z.string(),
    fact_value: z.string(),
    category: z.enum(['business', 'owner', 'team', 'product', 'customer', 'preference']).default('business'),
    source: z.enum(['owner', 'inferred', 'imported']).default('owner'),
    confidence: z.number().min(0).max(1).default(1),
    created_at: z.string(),
    updated_at: z.string(),
});
export const escalationSchema = z.object({
    id: z.string(),
    tenant_id: z.string(),
    approval_request_id: z.string().nullable().optional(),
    title: z.string(),
    context: z.string(),
    recommendation: z.string(),
    counterargument: z.string().nullable().optional(),
    alternatives: z.array(z.string()).default([]),
    risk_level: z.enum(['low', 'medium', 'high', 'critical']).default('medium'),
    status: z.enum(['pending', 'resolved', 'expired']).default('pending'),
    resolution: z.string().nullable().optional(),
    expires_at: z.string(),
    created_at: z.string(),
    resolved_at: z.string().nullable().optional(),
});
//# sourceMappingURL=types.js.map