{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://preclari.com/pif/v0.1/workflow-description.schema.json",
  "title": "PIF WorkflowDescription",
  "description": "A description of an AI workflow as the input to preflight assessment. PIF (Preflight Interchange Format) v0.1.",
  "type": "object",
  "required": [
    "pif_version",
    "workflow_id",
    "intent",
    "ai_role",
    "output_destination",
    "human_gate"
  ],
  "properties": {
    "pif_version": {
      "type": "string",
      "const": "0.1",
      "description": "Version of the PIF spec this document conforms to."
    },
    "workflow_id": {
      "type": "string",
      "pattern": "^[a-zA-Z0-9_:.-]{4,128}$",
      "description": "Stable identifier for this workflow. Used as the reference in PreflightAssertion.workflow_ref."
    },
    "title": {
      "type": "string",
      "maxLength": 200,
      "description": "Optional short human-readable title."
    },
    "intent": {
      "type": "string",
      "minLength": 10,
      "maxLength": 2000,
      "description": "Free-text description of what the workflow is intended to do, in plain language."
    },
    "intent_tags": {
      "type": "array",
      "items": { "type": "string" },
      "description": "Optional structured tags categorizing the workflow (e.g., quality_deviation_triage, sop_drafting)."
    },
    "ai_role": {
      "type": "string",
      "enum": [
        "decision",
        "recommendation",
        "draft",
        "classification",
        "extraction",
        "copilot",
        "summarization"
      ],
      "description": "What the AI is asked to do in the workflow. 'decision' = AI makes the final call; 'recommendation' = AI proposes, human approves; 'draft' = AI produces content for human edit; 'classification' = AI assigns categories; 'extraction' = AI pulls structured data; 'copilot' = AI suggests within human-driven workflow; 'summarization' = AI condenses content."
    },
    "data_classes": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "gxp_record",
          "pii",
          "phi",
          "manufacturing_data",
          "clinical_data",
          "regulatory_submission",
          "quality_data",
          "safety_data",
          "supply_chain_data",
          "commercial_data",
          "other"
        ]
      },
      "uniqueItems": true,
      "description": "Categories of data the workflow touches."
    },
    "jurisdictions": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^[A-Z]{2,5}$"
      },
      "uniqueItems": true,
      "description": "ISO 3166 alpha-2 country codes or recognized supranational codes (EU, ICH, WHO, PICS). Defines which regulatory contexts apply."
    },
    "output_destination": {
      "type": "string",
      "enum": [
        "advisory",
        "regulated_decision",
        "system_of_record",
        "draft_for_review",
        "automated_action",
        "archive"
      ],
      "description": "Where the AI's output flows after generation. 'advisory' = informs a human; 'regulated_decision' = becomes part of a GxP decision; 'system_of_record' = written to a controlled system; 'draft_for_review' = human edits before use; 'automated_action' = triggers downstream action without human review; 'archive' = stored but not actioned."
    },
    "human_gate": {
      "type": "string",
      "enum": ["none", "review", "approve_each", "approve_batch", "post_hoc_audit"],
      "description": "Human checkpoint design. 'none' = no human in loop; 'review' = optional human review; 'approve_each' = every output requires approval; 'approve_batch' = batch approval; 'post_hoc_audit' = sampling-based audit after the fact."
    },
    "reversibility": {
      "type": "string",
      "enum": ["reversible", "partial", "irreversible"],
      "description": "Can the action triggered by this workflow be reversed if found to be wrong?"
    },
    "lifecycle_stage": {
      "type": "string",
      "enum": ["design", "pilot", "production", "retirement"],
      "description": "Where the workflow sits in its lifecycle. Affects which regulatory expectations apply."
    },
    "risk_tolerance": {
      "type": "string",
      "enum": ["very_low", "low", "medium", "high"],
      "description": "Stated risk tolerance of the workflow owner. Used to calibrate which controls are recommended vs. required."
    },
    "gxp_domains_self_declared": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "GMP", "GDP", "GCP", "GLP", "GVP",
          "CSV", "data_integrity", "quality_systems",
          "regulatory_affairs", "pharmacovigilance", "labeling",
          "none_claimed"
        ]
      },
      "uniqueItems": true,
      "description": "GxP domains the workflow owner believes the workflow touches. The preflight may identify additional domains."
    },
    "context_notes": {
      "type": "string",
      "maxLength": 5000,
      "description": "Free-text additional context: existing controls, integration points, prior assessments, organizational constraints."
    },
    "extensions": {
      "type": "object",
      "description": "Implementation-specific extensions. Field names should be prefixed with the implementing tool (e.g., 'preclari:custom_field'). Implementations MUST NOT reject documents containing unknown extensions."
    }
  },
  "additionalProperties": false
}
