import type { JsonObject } from "../browser-types";

export const EFFECT_LOCK_PROFILE =
  "bulla.complete-effect-mediation/0.1-experimental" as const;
export const REDEMPTION_PROFILE =
  "bulla.effect-redemption/0.1-experimental" as const;
export const EFFECT_LOCK_REPORT_PROFILE =
  "bulla.complete-effect-mediation-report/0.1-experimental" as const;

export const EFFECT_CLASS = "sandbox.append" as const;
export const EFFECT_TARGET =
  "durable-object://locked-synthetic-receiver/sandbox.append" as const;
export const EFFECT_VALUE = "alpha-mediated" as const;
export const RECEIVER_ID = "effect-lock-receiver-01" as const;
export const COUNTERPARTY_ID = "effect-lock-counterparty-01" as const;
export const RUN_ID = "run-01500000-0000-4000-8000-000000000001" as const;
export const GRANT_ID = "grant-01500000-0000-4000-8000-000000000001" as const;
export const MANDATE_ID = "mandate-01500000-0000-4000-8000-000000000001" as const;
export const RECEIVER_NONCE = "receiver-nonce-015-0001" as const;
export const SEMANTIC_EPOCH = "effect-lock-semantics-1" as const;
export const VALID_FROM = "2026-01-01T00:00:00.000Z" as const;
export const VALID_UNTIL = "2027-01-01T00:00:00.000Z" as const;

export const EFFECT_ARGUMENTS: JsonObject = { value: EFFECT_VALUE };

export const EVIDENCE_POLICY: JsonObject = {
  profile: "bulla.complete-effect-mediation-policy/0.1-experimental",
  required_actions: ["eval.run.authorize", "boundary.decision"],
  required_decision: "PERMIT",
  effect_class: EFFECT_CLASS,
  use_limit: 1,
};

export const VERIFIER_DEFINITION: JsonObject = {
  profile: "bulla.complete-effect-mediation-verifier/0.1-experimental",
  canonicalization: "bulla-jcs-int/1",
  receipt_schema: "0.4",
  target_verifies: true,
};

const DECLARED_RUNTIME_GRAPH_TEMPLATE: JsonObject = {
  profile: "bulla.complete-effect-mediation-runtime-graph/0.1-experimental",
  protected_node: "protected_append_commit",
  nodes: [
    "grant_issue",
    "redemption_receive",
    "target_verify",
    "grant_consume",
    "protected_append_commit",
    "effect_record_persist",
    "state_read",
    "effect_read",
  ],
  transitions: [
    ["grant_issue", "redemption_receive"],
    ["redemption_receive", "target_verify"],
    ["target_verify", "grant_consume"],
    ["grant_consume", "protected_append_commit"],
    ["protected_append_commit", "effect_record_persist"],
  ],
  public_routes: {
    "POST /grants": "grant_issue",
    "POST /redemptions": "redemption_receive",
    "GET /state": "state_read",
    "GET /effect": "effect_read",
  },
};

export function declaredRuntimeGraph(): JsonObject {
  return structuredClone(DECLARED_RUNTIME_GRAPH_TEMPLATE);
}
