import { isoFromNow, stableId, DEMO_ORG, MS_DAY } from './shared-utils.js';

const teachingAgents = [
  { id: 'new-operator',      name: 'New Operator' },
  { id: 'security-lead',     name: 'Security Lead' },
  { id: 'sdk-developer',     name: 'SDK Developer' },
  { id: 'platform-engineer', name: 'Platform Engineer' },
  { id: 'compliance-officer', name: 'Compliance Officer' },
];

function agent(index) {
  return teachingAgents[index % teachingAgents.length];
}

const assumptions = [
  // ── Invalidated assumptions (misconceptions) ─────────────────────────
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 1),
    action_id: null,
    assumption: 'All actions require guard checks',
    basis: 'first-time setup confusion',
    validated: 0,
    invalidated: 1,
    invalidated_reason: 'Guard mode can be set to "off" for low-risk operations. Not every action needs a guard check — it depends on the policy configuration.',
    created_at: isoFromNow(44 * MS_DAY),
    invalidated_at: isoFromNow(41 * MS_DAY),
    agent_id: agent(0).id,
    agent_name: agent(0).name,
    declared_goal: 'Understanding when guard checks are required',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 2),
    action_id: null,
    assumption: 'Compliance mapping requires manual entry for every control',
    basis: 'assumption from traditional compliance tools',
    validated: 0,
    invalidated: 1,
    invalidated_reason: 'DashClaw auto-maps policies to framework controls. Manual mapping is only needed for controls without a matching policy.',
    created_at: isoFromNow(43 * MS_DAY),
    invalidated_at: isoFromNow(40 * MS_DAY),
    agent_id: agent(4).id,
    agent_name: agent(4).name,
    declared_goal: 'Setting up SOC 2 compliance mapping',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 3),
    action_id: null,
    assumption: 'risk_score above 70 always blocks the action',
    basis: 'misreading guard documentation',
    validated: 0,
    invalidated: 1,
    invalidated_reason: 'A risk_score above 70 does not automatically block. The outcome depends on policy config — it could warn, require approval, or block depending on the guard mode and thresholds.',
    created_at: isoFromNow(42 * MS_DAY),
    invalidated_at: isoFromNow(39 * MS_DAY),
    agent_id: agent(1).id,
    agent_name: agent(1).name,
    declared_goal: 'Configuring risk thresholds for production actions',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 4),
    action_id: null,
    assumption: 'Agents must be paired before recording actions',
    basis: 'confused pairing with registration',
    validated: 0,
    invalidated: 1,
    invalidated_reason: 'Pairing is optional — it adds signature verification for stronger identity binding, but agents can record actions with just registration.',
    created_at: isoFromNow(41 * MS_DAY),
    invalidated_at: isoFromNow(38 * MS_DAY),
    agent_id: agent(3).id,
    agent_name: agent(3).name,
    declared_goal: 'Onboarding a new agent to the platform',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 5),
    action_id: null,
    assumption: 'Demo mode requires a database connection',
    basis: 'assumed all modes need DB',
    validated: 0,
    invalidated: 1,
    invalidated_reason: 'Demo mode uses fixture data served by middleware — no database connection is needed. Set DASHCLAW_MODE=demo to run without any database.',
    created_at: isoFromNow(40 * MS_DAY),
    invalidated_at: isoFromNow(37 * MS_DAY),
    agent_id: agent(2).id,
    agent_name: agent(2).name,
    declared_goal: 'Running DashClaw locally for evaluation',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 6),
    action_id: null,
    assumption: 'The SDK only supports Node.js',
    basis: 'only saw Node docs initially',
    validated: 0,
    invalidated: 1,
    invalidated_reason: 'Both Node.js and Python SDKs are available. The Python SDK uses snake_case conventions while the Node SDK uses camelCase.',
    created_at: isoFromNow(38 * MS_DAY),
    invalidated_at: isoFromNow(36 * MS_DAY),
    agent_id: agent(2).id,
    agent_name: agent(2).name,
    declared_goal: 'Choosing an SDK for a Python-based agent',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 7),
    action_id: null,
    assumption: 'Guard semantic rules require an OpenAI API key',
    basis: 'assumed OpenAI dependency',
    validated: 0,
    invalidated: 1,
    invalidated_reason: 'The guard uses whatever LLM provider you configure. It is not limited to OpenAI — any compatible provider works.',
    created_at: isoFromNow(37 * MS_DAY),
    invalidated_at: isoFromNow(34 * MS_DAY),
    agent_id: agent(1).id,
    agent_name: agent(1).name,
    declared_goal: 'Setting up semantic guard rules',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 8),
    action_id: null,
    assumption: 'Webhooks are required for DashClaw to work',
    basis: 'confused with event-driven architectures',
    validated: 0,
    invalidated: 1,
    invalidated_reason: 'Webhooks are optional — they add push notifications for events, but the core platform works fully without them. Agents poll or use the SDK directly.',
    created_at: isoFromNow(35 * MS_DAY),
    invalidated_at: isoFromNow(33 * MS_DAY),
    agent_id: agent(3).id,
    agent_name: agent(3).name,
    declared_goal: 'Integrating DashClaw with an existing CI/CD pipeline',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 9),
    action_id: null,
    assumption: 'Each agent needs its own API key',
    basis: 'assumed per-agent auth',
    validated: 0,
    invalidated: 1,
    invalidated_reason: 'Agents share the org-level API key. Individual agents are identified by their agent_id header, not separate keys.',
    created_at: isoFromNow(33 * MS_DAY),
    invalidated_at: isoFromNow(31 * MS_DAY),
    agent_id: agent(0).id,
    agent_name: agent(0).name,
    declared_goal: 'Provisioning API access for a fleet of agents',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 10),
    action_id: null,
    assumption: 'Context threads and message threads are the same thing',
    basis: 'similar naming convention',
    validated: 0,
    invalidated: 1,
    invalidated_reason: 'Context threads (ct_*) are workspace observations for agent reasoning. Message threads (mt_*) are for agent-to-agent or agent-to-operator communication. They serve different purposes.',
    created_at: isoFromNow(30 * MS_DAY),
    invalidated_at: isoFromNow(28 * MS_DAY),
    agent_id: agent(2).id,
    agent_name: agent(2).name,
    declared_goal: 'Understanding the workspace data model',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 11),
    action_id: null,
    assumption: 'Handoffs happen automatically at session end',
    basis: 'assumed automatic session tracking',
    validated: 0,
    invalidated: 1,
    invalidated_reason: 'Handoffs require explicit creation via the SDK — nothing is automatic. The agent must call the handoff endpoint with context, status, and next steps.',
    created_at: isoFromNow(28 * MS_DAY),
    invalidated_at: isoFromNow(25 * MS_DAY),
    agent_id: agent(3).id,
    agent_name: agent(3).name,
    declared_goal: 'Setting up agent session continuity',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 12),
    action_id: null,
    assumption: 'cost_estimate is calculated by DashClaw',
    basis: 'assumed server-side cost calculation',
    validated: 0,
    invalidated: 1,
    invalidated_reason: 'cost_estimate is provided by the calling agent — DashClaw records and aggregates it but does not compute costs. The agent is responsible for tracking its own cost.',
    created_at: isoFromNow(25 * MS_DAY),
    invalidated_at: isoFromNow(23 * MS_DAY),
    agent_id: agent(0).id,
    agent_name: agent(0).name,
    declared_goal: 'Understanding cost analytics accuracy',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 13),
    action_id: null,
    assumption: 'Guard decisions are permanent',
    basis: 'assumed immutable decisions',
    validated: 0,
    invalidated: 1,
    invalidated_reason: 'Pending approval decisions can be approved or denied by operators. While completed decisions are recorded for audit, the approval workflow allows human intervention.',
    created_at: isoFromNow(22 * MS_DAY),
    invalidated_at: isoFromNow(20 * MS_DAY),
    agent_id: agent(1).id,
    agent_name: agent(1).name,
    declared_goal: 'Understanding the operator approval workflow',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 14),
    action_id: null,
    assumption: 'You need admin role to view the dashboard',
    basis: 'assumed restrictive access model',
    validated: 0,
    invalidated: 1,
    invalidated_reason: 'Members can view the dashboard and most operational data. Admin role is only required for settings, team management, and destructive operations.',
    created_at: isoFromNow(18 * MS_DAY),
    invalidated_at: isoFromNow(16 * MS_DAY),
    agent_id: agent(0).id,
    agent_name: agent(0).name,
    declared_goal: 'Setting up team access for new operators',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 15),
    action_id: null,
    assumption: 'Learning recommendations are mandatory',
    basis: 'assumed enforced recommendations',
    validated: 0,
    invalidated: 1,
    invalidated_reason: 'Recommendations are advisory — agents can override them by providing a reason. This supports agent autonomy while maintaining an audit trail.',
    created_at: isoFromNow(15 * MS_DAY),
    invalidated_at: isoFromNow(13 * MS_DAY),
    agent_id: agent(4).id,
    agent_name: agent(4).name,
    declared_goal: 'Configuring learning analytics for agent improvement',
  },

  // ── Validated assumptions (correct understandings) ────────────────────
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 16),
    action_id: null,
    assumption: 'API keys should be stored in environment variables, not code',
    basis: 'SDK documentation',
    validated: 1,
    invalidated: 0,
    invalidated_reason: null,
    created_at: isoFromNow(44 * MS_DAY),
    invalidated_at: null,
    agent_id: agent(1).id,
    agent_name: agent(1).name,
    declared_goal: 'Establishing secure credential management practices',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 17),
    action_id: null,
    assumption: 'Guard enforce mode blocks non-compliant actions before they execute',
    basis: 'guard documentation',
    validated: 1,
    invalidated: 0,
    invalidated_reason: null,
    created_at: isoFromNow(43 * MS_DAY),
    invalidated_at: null,
    agent_id: agent(1).id,
    agent_name: agent(1).name,
    declared_goal: 'Configuring pre-execution guardrails',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 18),
    action_id: null,
    assumption: 'Every action gets a unique action_id with the act_ prefix',
    basis: 'observed in API responses',
    validated: 1,
    invalidated: 0,
    invalidated_reason: null,
    created_at: isoFromNow(42 * MS_DAY),
    invalidated_at: null,
    agent_id: agent(2).id,
    agent_name: agent(2).name,
    declared_goal: 'Understanding ID formats across the platform',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 19),
    action_id: null,
    assumption: 'The risk_score range is 0 to 100',
    basis: 'API documentation',
    validated: 1,
    invalidated: 0,
    invalidated_reason: null,
    created_at: isoFromNow(40 * MS_DAY),
    invalidated_at: null,
    agent_id: agent(3).id,
    agent_name: agent(3).name,
    declared_goal: 'Implementing risk scoring in agent logic',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 20),
    action_id: null,
    assumption: 'Handoffs preserve context between agent sessions',
    basis: 'workspace documentation',
    validated: 1,
    invalidated: 0,
    invalidated_reason: null,
    created_at: isoFromNow(38 * MS_DAY),
    invalidated_at: null,
    agent_id: agent(3).id,
    agent_name: agent(3).name,
    declared_goal: 'Designing multi-session agent workflows',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 21),
    action_id: null,
    assumption: 'Compliance evidence is generated automatically from guard decisions',
    basis: 'compliance framework documentation',
    validated: 1,
    invalidated: 0,
    invalidated_reason: null,
    created_at: isoFromNow(36 * MS_DAY),
    invalidated_at: null,
    agent_id: agent(4).id,
    agent_name: agent(4).name,
    declared_goal: 'Automating compliance evidence collection',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 22),
    action_id: null,
    assumption: 'The org_id header is injected by middleware, not by the client',
    basis: 'security model documentation',
    validated: 1,
    invalidated: 0,
    invalidated_reason: null,
    created_at: isoFromNow(35 * MS_DAY),
    invalidated_at: null,
    agent_id: agent(1).id,
    agent_name: agent(1).name,
    declared_goal: 'Understanding the trust boundary for org context',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 23),
    action_id: null,
    assumption: 'Snippets track use_count for popularity',
    basis: 'observed in snippet API responses',
    validated: 1,
    invalidated: 0,
    invalidated_reason: null,
    created_at: isoFromNow(32 * MS_DAY),
    invalidated_at: null,
    agent_id: agent(2).id,
    agent_name: agent(2).name,
    declared_goal: 'Building a snippet recommendation system',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 24),
    action_id: null,
    assumption: 'Security signals have severity levels: red and amber',
    basis: 'security dashboard observation',
    validated: 1,
    invalidated: 0,
    invalidated_reason: null,
    created_at: isoFromNow(29 * MS_DAY),
    invalidated_at: null,
    agent_id: agent(1).id,
    agent_name: agent(1).name,
    declared_goal: 'Triaging security signals by severity',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 25),
    action_id: null,
    assumption: 'Task routing matches required_skills to agent capabilities',
    basis: 'routing documentation',
    validated: 1,
    invalidated: 0,
    invalidated_reason: null,
    created_at: isoFromNow(26 * MS_DAY),
    invalidated_at: null,
    agent_id: agent(3).id,
    agent_name: agent(3).name,
    declared_goal: 'Configuring skill-based task assignment',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 26),
    action_id: null,
    assumption: 'Memory health score drops when context files have duplicates or stale entries',
    basis: 'memory health API response',
    validated: 1,
    invalidated: 0,
    invalidated_reason: null,
    created_at: isoFromNow(23 * MS_DAY),
    invalidated_at: null,
    agent_id: agent(3).id,
    agent_name: agent(3).name,
    declared_goal: 'Monitoring workspace memory quality',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 27),
    action_id: null,
    assumption: 'Webhook deliveries include response status codes for debugging',
    basis: 'webhook API documentation',
    validated: 1,
    invalidated: 0,
    invalidated_reason: null,
    created_at: isoFromNow(19 * MS_DAY),
    invalidated_at: null,
    agent_id: agent(2).id,
    agent_name: agent(2).name,
    declared_goal: 'Debugging failed webhook deliveries',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 28),
    action_id: null,
    assumption: 'Learning velocity measures score improvement rate over time',
    basis: 'learning analytics documentation',
    validated: 1,
    invalidated: 0,
    invalidated_reason: null,
    created_at: isoFromNow(14 * MS_DAY),
    invalidated_at: null,
    agent_id: agent(4).id,
    agent_name: agent(4).name,
    declared_goal: 'Tracking agent learning progress across sessions',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 29),
    action_id: null,
    assumption: 'Policy test results don\'t affect real guard decisions',
    basis: 'policy test documentation',
    validated: 1,
    invalidated: 0,
    invalidated_reason: null,
    created_at: isoFromNow(8 * MS_DAY),
    invalidated_at: null,
    agent_id: agent(0).id,
    agent_name: agent(0).name,
    declared_goal: 'Safely testing new guard policies before deployment',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_tutorial', 30),
    action_id: null,
    assumption: 'Agent maturity levels progress: developing → competent → proficient',
    basis: 'learning analytics documentation',
    validated: 1,
    invalidated: 0,
    invalidated_reason: null,
    created_at: isoFromNow(3 * MS_DAY),
    invalidated_at: null,
    agent_id: agent(4).id,
    agent_name: agent(4).name,
    declared_goal: 'Understanding agent growth trajectories',
  },

  // ── Active assumptions (unvalidated) ────────────────────────────────
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_active', 1),
    action_id: 'act_demo_current_1',
    assumption: 'Database connection pool is sufficient for high-concurrency rollout',
    basis: 'Static config review',
    validated: 0,
    invalidated: 0,
    created_at: isoFromNow(10 * 60 * 1000), // 10m ago
    agent_id: 'agent_deployment_bot_01',
    agent_name: 'Deployment Bot',
    declared_goal: 'Rolling out production-api v2.4.1',
  },
  {
    org_id: DEMO_ORG,
    assumption_id: stableId('asm_active', 2),
    action_id: 'act_demo_current_2',
    assumption: 'No breaking changes in the latest API spec upstream',
    basis: 'CI pipeline check passed',
    validated: 0,
    invalidated: 0,
    created_at: isoFromNow(25 * 60 * 1000), // 25m ago
    agent_id: 'api_monitor_02',
    agent_name: 'API Monitor',
    declared_goal: 'Verifying upstream dependencies',
  },
];

export { assumptions };
