{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/api-evangelist/certifyos/main/json-schema/certifyos-add-state-to-credential-response-schema.json",
  "title": "AddStateToCredentialResponse",
  "description": "Outcome of adding a flag's state to the practitioner's states to credential",
  "x-generated": "2026-10-20",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/certifyos-flag-api-openapi.yml#/components/schemas/AddStateToCredentialResponse",
  "type": "object",
  "properties": {
    "status": {
      "type": "string",
      "description": "SUCCESS | PARTIAL_SUCCESS | FAILED"
    },
    "states": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "State(s) actioned — the flag's single metaData.state, or for a compact-license flag, the reviewer's validated selection"
    },
    "statesResult": {
      "$ref": "#/$defs/StatesResult",
      "type": "object",
      "description": "Practitioner states-to-credential write outcome"
    },
    "flagResult": {
      "$ref": "#/$defs/FlagResult",
      "type": "object",
      "description": "Flag move-to-seen outcome; attempted=false when skipped"
    },
    "monitoringWorkflowResult": {
      "$ref": "#/$defs/WorkflowResult",
      "type": "object",
      "description": "Monitoring workflow update outcome; attempted=false when skipped"
    }
  },
  "$defs": {
    "FlagResult": {
      "type": "object",
      "description": "Flag move-to-seen outcome",
      "properties": {
        "attempted": {
          "type": "boolean",
          "description": "Whether the move was attempted"
        },
        "ok": {
          "type": "boolean",
          "description": "Whether the flag was moved"
        },
        "flagId": {
          "type": "string",
          "description": "The flag id"
        },
        "status": {
          "type": "string",
          "description": "The resulting status, when moved"
        },
        "noteRecorded": {
          "type": [
            "boolean",
            "null"
          ],
          "description": "Only when the status is not moved and a note was due (outreachInProgress; a Seen compact flag that added states): whether the note was stored on the flag history; null otherwise"
        }
      }
    },
    "StatesResult": {
      "type": "object",
      "description": "Practitioner states-to-credential write outcome",
      "properties": {
        "attempted": {
          "type": "boolean",
          "description": "Whether the write was attempted"
        },
        "ok": {
          "type": "boolean",
          "description": "Whether the state is now on the practitioner"
        },
        "added": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "States actually appended"
        },
        "resulting": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "States to credential afterwards; empty, never null"
        },
        "slicesUpdated": {
          "type": "integer",
          "format": "int32",
          "description": "Contributing slices written (0 or 1)"
        },
        "alreadyPresent": {
          "type": "boolean",
          "description": "The state was already present; nothing written"
        },
        "detail": {
          "type": "string",
          "description": "Failure detail when ok is false"
        }
      }
    },
    "WorkflowResult": {
      "type": "object",
      "description": "Monitoring workflow update outcome",
      "properties": {
        "attempted": {
          "type": "boolean",
          "description": "Whether the update was attempted"
        },
        "ok": {
          "type": "boolean",
          "description": "Whether the write and recalculation both succeeded"
        },
        "workflowId": {
          "type": "string",
          "description": "The workflow updated, or null when none is active"
        },
        "sectionsReevaluated": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Flag sections recalculated"
        }
      }
    }
  }
}