/**
 * Deterministic seed dataset for local SQLite domains.
 *
 * Values are bounded, source-agnostic, and contain no real provider IDs, tokens,
 * paths, matcher keys, or audit fragments. They are safe to surface through
 * browser-visible projection contracts and are stable across reseed runs so
 * `applySeed` can be idempotent via INSERT OR IGNORE on the stable IDs.
 */
export const SEED_WORKSPACE_ID = "ws-seed-local";
export const SEED_WORKSPACE_ROOT_PATH = "/seed/workspace";
const SEED_BASE_INSTANT = "2026-05-21T08:00:00.000Z";
function shiftMinutes(base, minutes) {
    return new Date(new Date(base).getTime() + minutes * 60_000).toISOString();
}
/**
 * Build the deterministic seed dataset.
 *
 * Same input always produces the same dataset (identical IDs, timestamps, and
 * metadata). All strings are safe public values — no secrets, tokens, raw
 * paths, provider IDs, matcher keys, or audit identifiers.
 */
export function buildSeedDataset() {
    const workspace = {
        id: SEED_WORKSPACE_ID,
        rootPath: SEED_WORKSPACE_ROOT_PATH,
    };
    const runs = [
        {
            id: "run-seed-0001",
            workspaceId: SEED_WORKSPACE_ID,
            provider: "opencode",
            status: "running",
            title: "Seed run: web console issue triage",
            runtimeSessionId: "session-seed-0001",
            sourceWorkItemId: "WORK-SEED-001",
            sourceRepositoryId: "repo-seed-web-console",
            branchName: "seed/web-console-issue-triage",
            baseBranch: "main",
            capPolicy: {
                costUsdPerRun: 5,
                wallTimeSecondsPerRun: 900,
            },
        },
        {
            id: "run-seed-0002",
            workspaceId: SEED_WORKSPACE_ID,
            provider: "opencode",
            status: "completed",
            title: "Seed run: billing api proof draft",
            runtimeSessionId: "session-seed-0002",
            sourceWorkItemId: "WORK-SEED-002",
            sourceRepositoryId: "repo-seed-billing-api",
            branchName: "seed/billing-api-proof-draft",
            baseBranch: "main",
            capPolicy: {
                costUsdPerRun: 5,
                wallTimeSecondsPerRun: 900,
            },
        },
        {
            id: "run-seed-0003",
            workspaceId: SEED_WORKSPACE_ID,
            provider: "opencode",
            status: "blocked-budget",
            title: "Seed run: blocked by budget cap",
            runtimeSessionId: "session-seed-0003",
            sourceWorkItemId: "WORK-SEED-003",
            sourceRepositoryId: "repo-seed-web-console",
            branchName: "seed/blocked-by-budget-cap",
            baseBranch: "main",
            capPolicy: {
                costUsdPerRun: 1,
                wallTimeSecondsPerRun: 600,
            },
        },
    ];
    const runtimeEvents = [
        {
            id: "runtime-event-seed-0001",
            runId: "run-seed-0001",
            runtimeSessionId: "session-seed-0001",
            source: "opencode",
            type: "run-started",
            occurredAt: shiftMinutes(SEED_BASE_INSTANT, 0),
            title: "Run started",
            description: "Seeded local run started for verification.",
            tone: "primary",
            metadata: { category: "lifecycle" },
        },
        {
            id: "runtime-event-seed-0002",
            runId: "run-seed-0001",
            runtimeSessionId: "session-seed-0001",
            source: "opencode",
            type: "tool-call",
            occurredAt: shiftMinutes(SEED_BASE_INSTANT, 1),
            title: "Read project structure",
            description: "Seeded tool call summary; no raw paths or commands.",
            tone: "muted",
            metadata: { category: "tool" },
        },
        {
            id: "runtime-event-seed-0003",
            runId: "run-seed-0001",
            runtimeSessionId: "session-seed-0001",
            source: "opencode",
            type: "permission-requested",
            occurredAt: shiftMinutes(SEED_BASE_INSTANT, 2),
            title: "Permission requested",
            description: "Bounded summary for a seeded permission prompt.",
            tone: "warning",
            metadata: { category: "permission", risk: "medium" },
        },
        {
            id: "runtime-event-seed-0004",
            runId: "run-seed-0002",
            runtimeSessionId: "session-seed-0002",
            source: "opencode",
            type: "run-completed",
            occurredAt: shiftMinutes(SEED_BASE_INSTANT, 30),
            title: "Run completed",
            description: "Seeded local run completed with proof artifact.",
            tone: "success",
            metadata: { category: "lifecycle" },
        },
        {
            id: "runtime-event-seed-0005",
            runId: "run-seed-0003",
            runtimeSessionId: "session-seed-0003",
            source: "opencode",
            type: "run-blocked",
            occurredAt: shiftMinutes(SEED_BASE_INSTANT, 45),
            title: "Run blocked by cap",
            description: "Seeded run halted because the budget cap was reached.",
            tone: "destructive",
            metadata: { category: "lifecycle", status: "blocked-budget" },
        },
    ];
    const runEvidence = [
        {
            runId: "run-seed-0002",
            changedFiles: [
                {
                    path: "seed/src/example/module.ts",
                    change: "modified",
                    added: 12,
                    removed: 4,
                },
                {
                    path: "seed/src/example/module.test.ts",
                    change: "added",
                    added: 28,
                    removed: 0,
                },
            ],
            validations: [
                {
                    label: "Unit tests",
                    status: "passed",
                    kind: "test",
                    verdict: "pass",
                    exitCode: 0,
                    durationMs: 1240,
                    reasonCode: "all-tests-passed",
                },
                {
                    label: "Type check",
                    status: "passed",
                    kind: "typecheck",
                    verdict: "pass",
                    exitCode: 0,
                    durationMs: 880,
                    reasonCode: "no-type-errors",
                },
            ],
            warnings: [
                {
                    label: "Lint warning in seeded module",
                    severity: "info",
                },
            ],
        },
        {
            runId: "run-seed-0003",
            changedFiles: [
                {
                    path: "seed/src/example/blocked.ts",
                    change: "modified",
                    added: 2,
                    removed: 1,
                },
            ],
            validations: [
                {
                    label: "Budget cap",
                    status: "failed",
                    kind: "policy",
                    verdict: "blocked",
                    reasonCode: "budget-cap-reached",
                },
            ],
            warnings: [
                {
                    label: "Run halted before validations completed",
                    severity: "warning",
                },
            ],
        },
    ];
    const permissionEntries = [
        {
            requestId: "prq-seed-0001",
            decisionId: "pdec-seed-0001",
            runId: "run-seed-0001",
            runtimeSessionId: "session-seed-0001",
            auditId: "audit-seed-0001",
            selectedOption: "allow_for_session",
            opencodeReply: "always",
            scope: "session",
            effect: "allow",
            option: "allow_for_session",
            capabilities: ["read"],
            pattern: "read.project-files",
            toolName: "read.project-files",
            toolTitle: "Read project files",
            toolRisk: "read",
            inputPreview: "Seeded read summary, no raw path.",
            affectedPaths: ["seed/src/example"],
            reason: "Bounded summary for a seeded read approval.",
        },
        {
            requestId: "prq-seed-0002",
            decisionId: "pdec-seed-0002",
            runId: "run-seed-0001",
            runtimeSessionId: "session-seed-0001",
            auditId: "audit-seed-0002",
            selectedOption: "deny",
            opencodeReply: "reject",
            scope: "session",
            effect: "deny",
            option: "deny",
            capabilities: ["external-mutation"],
            pattern: "external.mutation",
            toolName: "external.mutation",
            toolTitle: "External service mutation",
            toolRisk: "external-mutation",
            inputPreview: "Seeded external mutation summary, no raw command.",
            affectedPaths: [],
            reason: "Deny-only diagnostics for a seeded external mutation.",
        },
    ];
    return {
        workspace,
        runs,
        runtimeEvents,
        runEvidence,
        permissionEntries,
        repositories: [
            {
                id: "repo-bind-seed-0001",
                workspaceId: SEED_WORKSPACE_ID,
                displayLabel: "Billing API",
                provider: "github",
                status: "connected",
                lastSyncLabel: "Synced moments ago",
            },
            {
                id: "repo-bind-seed-0002",
                workspaceId: SEED_WORKSPACE_ID,
                displayLabel: "Customer Portal",
                provider: "github",
                status: "syncing",
                lastSyncLabel: "Syncing now",
            },
            {
                id: "repo-bind-seed-0003",
                workspaceId: SEED_WORKSPACE_ID,
                displayLabel: "Legacy ETL",
                provider: "github",
                status: "needs-action",
                lastErrorCode: "needs_oauth_refresh",
            },
        ],
        onboardingGates: [
            {
                id: "ob-gate-seed-account",
                workspaceId: SEED_WORKSPACE_ID,
                gate: "account",
                status: "ready",
                tone: "success",
                displayLabel: "Account ready",
            },
            {
                id: "ob-gate-seed-org",
                workspaceId: SEED_WORKSPACE_ID,
                gate: "organization",
                status: "ready",
                tone: "success",
                displayLabel: "Organization configured",
            },
            {
                id: "ob-gate-seed-github-app",
                workspaceId: SEED_WORKSPACE_ID,
                gate: "github_app",
                status: "in-progress",
                tone: "primary",
                displayLabel: "GitHub App installation in progress",
            },
            {
                id: "ob-gate-seed-repository",
                workspaceId: SEED_WORKSPACE_ID,
                gate: "repository",
                status: "blocked",
                tone: "warning",
                displayLabel: "Select at least one repository",
                lastErrorCode: "no_repository_selected",
            },
            {
                id: "ob-gate-seed-provider",
                workspaceId: SEED_WORKSPACE_ID,
                gate: "provider",
                status: "blocked",
                tone: "destructive",
                displayLabel: "Add a runtime provider",
                lastErrorCode: "no_provider_configured",
            },
            {
                id: "ob-gate-seed-bridge-pairing",
                workspaceId: SEED_WORKSPACE_ID,
                gate: "bridge_pairing",
                status: "ready",
                tone: "success",
                displayLabel: "Bridge paired",
            },
        ],
        settingsReadiness: [
            {
                id: "settings-seed-providers",
                workspaceId: SEED_WORKSPACE_ID,
                area: "providers",
                status: "needs-attention",
                tone: "warning",
                displayLabel: "Add a runtime provider",
                lastErrorCode: "no_provider_configured",
            },
            {
                id: "settings-seed-policies",
                workspaceId: SEED_WORKSPACE_ID,
                area: "policies",
                status: "ready",
                tone: "success",
                displayLabel: "Policies up to date",
            },
            {
                id: "settings-seed-permissions",
                workspaceId: SEED_WORKSPACE_ID,
                area: "permissions",
                status: "ready",
                tone: "success",
                displayLabel: "Permission ledger active",
            },
            {
                id: "settings-seed-billing",
                workspaceId: SEED_WORKSPACE_ID,
                area: "billing",
                status: "not-configured",
                tone: "muted",
                displayLabel: "Billing not configured",
            },
            {
                id: "settings-seed-notifications",
                workspaceId: SEED_WORKSPACE_ID,
                area: "notifications",
                status: "ready",
                tone: "success",
                displayLabel: "Notifications routed to email",
            },
        ],
        reviewQueue: [
            {
                id: "review-seed-pending",
                workspaceId: SEED_WORKSPACE_ID,
                runId: "run-seed-0001",
                status: "pending",
                riskTone: "warning",
                headline: "Pending reviewer attention",
                summaryLabel: "Awaiting human review",
            },
            {
                id: "review-seed-in-review",
                workspaceId: SEED_WORKSPACE_ID,
                runId: "run-seed-0002",
                status: "in-review",
                riskTone: "primary",
                headline: "Reviewer engaged",
                summaryLabel: "Risk discussion in progress",
            },
            {
                id: "review-seed-approved",
                workspaceId: SEED_WORKSPACE_ID,
                runId: "run-seed-0003",
                status: "approved",
                riskTone: "success",
                headline: "Approved with no changes",
                summaryLabel: "Cleared for merge",
            },
            {
                id: "review-seed-revoked",
                workspaceId: SEED_WORKSPACE_ID,
                status: "revoked",
                riskTone: "destructive",
                headline: "Approval revoked after incident",
                summaryLabel: "Revoked for follow-up",
            },
        ],
        reviewDecisions: [
            {
                id: "review-decision-seed-approved",
                workspaceId: SEED_WORKSPACE_ID,
                reviewId: "review-seed-approved",
                decision: "approve",
                reasonCode: "looks_good",
                noteLabel: "Approved by reviewer",
                decidedAtOffsetMinutes: 30,
            },
            {
                id: "review-decision-seed-revoked",
                workspaceId: SEED_WORKSPACE_ID,
                reviewId: "review-seed-revoked",
                decision: "revoke",
                reasonCode: "post_merge_incident",
                noteLabel: "Revoked after rollback",
                decidedAtOffsetMinutes: 45,
            },
        ],
    };
}
