// @generated by crates/nana-contracts; do not edit.

export type ResourceId = string;
export type ResourceKind =
  | "character"
  | "world_book"
  | "persona"
  | "plot_module"
  | "item_spec";

export interface ResourceRef {
  id: ResourceId;
  kind: ResourceKind;
  revision: string;
  content_hash: string;
}

export interface ResourceHeader {
  id: ResourceId;
  kind: ResourceKind;
  schema_version: number;
  revision: string;
  content_hash: string;
  dependencies: ResourceRef[];
}

export type RelationshipDimension =
  | "affinity"
  | "trust"
  | "hope"
  | "respect"
  | "intimacy"
  | "attachment";

export interface RelationshipAxes {
  affinity: number;
  trust: number;
  hope: number;
  respect: number;
  intimacy: number;
  attachment: number;
}

export interface RelationshipAdjustment {
  dimension: RelationshipDimension;
  delta: number;
  cause: string;
  judgment_rule: string | null;
}

export interface SkillValue {
  skill: string;
  value: number;
}

export interface CharacterCard {
  header: ResourceHeader;
  name: string;
  identity: string;
  personality: string[];
  values: string[];
  boundaries: string[];
  style: {
    speech: string;
    mannerisms: string[];
    forbidden_player_assumptions: string[];
  };
  initial_relationship: RelationshipAxes;
  judgment_rules: Array<{
    tags: string[];
    meaning: string;
    relationship_effects: RelationshipAdjustment[];
  }>;
  skills: SkillValue[];
  default_expression: string;
}

export interface WorldBook {
  header: ResourceHeader;
  name: string;
  entries: Array<{
    id: string;
    title: string;
    content: string;
    keywords: string[];
    tags: string[];
    required_flags: string[];
  }>;
}

export interface Persona {
  header: ResourceHeader;
  name: string;
  identity: string;
  traits: string[];
  skills: SkillValue[];
  initial_items: ResourceId[];
}

export interface PlotModule {
  header: ResourceHeader;
  name: string;
  opening_event: string;
  events: Array<{
    id: string;
    title: string;
    tags: string[];
    situation: string[];
    required_flags: string[];
    pressures: Array<{
      id: string;
      description: string;
      clock_id: string | null;
      clock_delta: number | null;
    }>;
    outcomes: Array<{
      id: string;
      description: string;
      effects: StateOp[];
    }>;
  }>;
}

export interface ItemSpec {
  header: ResourceHeader;
  name: string;
  description: string;
  tags: string[];
  lore_refs: string[];
  mechanics: {
    usable: boolean;
    grants_tags: string[];
    check_modifier: number | null;
  };
  hidden_facts: string[];
}

export interface ResourceBundle {
  id: string;
  schema_version: number;
  revision: string;
  display_name: string;
  entry_character: ResourceId;
  entry_persona: ResourceId;
  entry_plot_module: ResourceId | null;
  characters: CharacterCard[];
  world_books: WorldBook[];
  personas: Persona[];
  plot_modules: PlotModule[];
  item_specs: ItemSpec[];
}

export type PromiseStatus =
  | "proposed"
  | "accepted"
  | "fulfilled"
  | "broken"
  | "released"
  | "impossible";
export type PromiseWeight = "minor" | "major";
export type KnowledgeCertainty = "suspected" | "reported" | "confirmed";
export type ItemPlacement = "bag" | "worn" | "hand" | "scene" | "hidden";
export type AcquisitionMode = "initial" | "found" | "given" | "borrowed" | "stolen" | "returned";

export interface Promise {
  id: string;
  promiser: string;
  promisee: string;
  content: string;
  status: PromiseStatus;
  weight: PromiseWeight;
  created_at: string;
  accepted_at: string | null;
  resolved_at: string | null;
}

export interface KnowledgeRecord {
  id: string;
  observer: string;
  subject: string | null;
  fact: string;
  certainty: KnowledgeCertainty;
  source: string;
  learned_at: string;
  last_verified_at: string | null;
}

export interface ItemInstance {
  id: string;
  spec_ref: ResourceId;
  owner: string;
  holder: string;
  placement: ItemPlacement;
  quantity: number;
  condition: string;
  state_tags: string[];
  acquisition: {
    mode: AcquisitionMode;
    from: string | null;
    at_node: string;
  };
}

export interface RuntimeState {
  story_id: string;
  current_node: string;
  current_branch: string;
  world_flags: Record<string, boolean>;
  relationships: Record<string, RelationshipAxes>;
  relationship_states: unknown[];
  promises: Promise[];
  knowledge: KnowledgeRecord[];
  items: ItemInstance[];
  clocks: unknown[];
  checks: unknown[];
}

export type StateOp =
  | { op: "set_world_flag"; key: string; value: boolean }
  | { op: "adjust_relationship"; from: string; to: string; adjustment: RelationshipAdjustment }
  | { op: "create_promise"; promise: Promise }
  | { op: "update_promise"; promise_id: string; status: PromiseStatus; resolved_at: string | null }
  | { op: "add_knowledge"; record: KnowledgeRecord }
  | { op: "add_item"; item: ItemInstance }
  | {
      op: "transfer_item";
      item_id: string;
      from: string;
      to: string;
      placement: ItemPlacement;
      mode: AcquisitionMode;
    }
  | { op: "record_check"; check: unknown }
  | { op: "advance_clock"; clock_id: string; delta: number };

export type BeatKind = "narration" | "dialogue" | "action" | "system";

export interface PresentationBeat {
  id: string;
  kind: BeatKind;
  speaker: string | null;
  text: string;
  visual: {
    character: string | null;
    expression: string | null;
    pose: string | null;
    scene: string | null;
  } | null;
}

export type RelationshipBand = "distant" | "guarded" | "warming" | "close" | "bonded";

export interface RelationshipView {
  affinity: RelationshipBand;
  trust: RelationshipBand;
  hope: RelationshipBand;
  respect: RelationshipBand;
  intimacy: RelationshipBand;
  attachment: RelationshipBand;
  updatedAtNode: string | null;
}

export interface PlayerView {
  storyId: string;
  nodeId: string;
  branchId: string;
  sceneId: string;
  sceneTitle: string;
  characterName: string;
  beats: PresentationBeat[];
  suggestions: Array<{ id: string; label: string; draft: string }>;
  inventory: Array<{
    instanceId: string;
    name: string;
    description: string;
    quantity: number;
    placement: ItemPlacement;
    condition: string;
  }>;
  knowledge: Array<{
    id: string;
    title: string;
    summary: string;
    certainty: KnowledgeCertainty;
  }>;
  promises: Array<{
    id: string;
    content: string;
    status: PromiseStatus;
    weight: PromiseWeight;
  }>;
  relationship: RelationshipView;
  history: Array<{
    id: string;
    parentId: string | null;
    branchId: string;
    label: string;
    isCurrent: boolean;
  }>;
  canContinue: boolean;
}

export type TurnIntent = "speak_or_act" | "continue" | "regenerate" | "push_check";

export interface TurnRequest {
  storyId: string;
  branchId: string;
  expectedNodeId: string;
  actionId: string;
  intent: TurnIntent;
  input: string;
}

export interface TurnResult {
  committedNodeId: string;
  playerView: PlayerView;
}

export type TurnFailureCode =
  | "stale_node"
  | "invalid_input"
  | "invalid_model_output"
  | "provider_unavailable"
  | "cancelled"
  | "timed_out"
  | "internal";

export interface TurnFailure {
  code: TurnFailureCode;
  message: string;
  retryable: boolean;
}

export interface AppInfo {
  name: string;
  version: string;
  contractVersion: number;
}

export interface DemoPackSummary {
  id: string;
  displayName: string;
  revision: string;
  characters: number;
  worldBooks: number;
  personas: number;
  plotModules: number;
  itemSpecs: number;
}
