import type { ActionReceiptV04 } from "../receipt";
import type { JsonObject } from "../types";
import type { Env } from "../types";

export interface EffectLockEnv extends Env {
  LOCKED_SYNTHETIC_RECEIVER: DurableObjectNamespace;
  EFFECT_LOCK_ISSUANCE_TOKEN?: string;
  EFFECT_LOCK_TEST_MODE?: "true" | "false";
  EFFECT_LOCK_FIXED_TIME?: string;
  EFFECT_LOCK_FIXED_OBSERVATION_ID?: string;
}

export interface AcceptedEffectLockContext {
  profile: "bulla.complete-effect-mediation/0.1-experimental";
  receiver_issuer: string;
  authorization_issuer: string;
  boundary_issuer: string;
  evidence_policy_hash: string;
  verifier_hash: string;
  runtime_graph_root: string;
  role_set_hash: string;
  semantic_epoch: string;
  authority_epoch: string;
}

export interface RedemptionWire extends JsonObject {
  profile: "bulla.effect-redemption/0.1-experimental";
  grant: JsonObject;
  mandate: JsonObject;
  boundary_decision: JsonObject;
  authzen_request: JsonObject;
  authzen_response: JsonObject;
  effect_arguments: JsonObject;
  receiver_nonce: string;
  evidence_bundle_root: string;
}

export interface VerifiedRedemption {
  grant: ActionReceiptV04;
  redemption: RedemptionWire;
  redemption_digest: string;
  grant_attestation: string;
  effect_arguments_hash: string;
  prior_state_root: string;
}

export interface EffectRecordSubject extends JsonObject {
  profile: "bulla.complete-effect-mediation/0.1-experimental";
  grant_attestation: string;
  redemption_digest: string;
  effect_class: "sandbox.append";
  arguments_hash: string;
  run_id: string;
  receiver_id: string;
  target: string;
  evidence_policy_hash: string;
  verifier_hash: string;
  runtime_graph_root: string;
  role_set_hash: string;
  semantic_epoch: string;
  authority_epoch: string;
  previous_state_root: string;
  new_state_root: string;
  observation_id: string;
  issuer_role: "target";
}

export interface RedemptionResponse extends JsonObject {
  profile: "bulla.effect-redemption/0.1-experimental";
  status: "COMMITTED";
  grant_status: "CONSUMED";
  replay: boolean;
  observation_id: string;
  prior_state_root: string;
  new_state_root: string;
  redemption_digest: string;
  effect_record: JsonObject;
}
