{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.mpai.community/PGM1/V1.0/data/AUCBKN.json",
  "title": "AUC-BKN V1.0",
  "description": "The Data Type exchanged between A-User Control (AUC) and Basic Knowledge (BKN). It has two modes, told apart by Mode: Request (RQ), sent by AUC to BKN (previously BKN Directive), and Response (RS), sent by BKN to AUC (previously BKN Status). Basic Knowledge is a reasoning AIM and is not Composite: it decides its own conclusion, and says whether it adopted the correction proposed by AUC. AUC may ask it to propose Process Actions in addition to the Final Response; the Final Response and the Process Actions are sent on its output Ports and the Response only reports them. Every Request is answered by a Response.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "Header",
    "Mode",
    "MInstance",
    "UEnvironment",
    "SessionID",
    "AUCBKNID",
    "AUCBKNTime"
  ],
  "properties": {
    "Header": {
      "type": "string",
      "const": "PGM-UCK-V1.0"
    },
    "Mode": {
      "type": "string",
      "enum": [
        "RQ",
        "RS"
      ],
      "description": "RQ: Request (AUC to BKN), the old BKN Directive. RS: Response (BKN to AUC), the old BKN Status."
    },
    "MInstance": {
      "type": "string",
      "description": "Identifier of the M-Instance."
    },
    "UEnvironment": {
      "type": "string",
      "description": "Identifier of the U-Environment."
    },
    "SessionID": {
      "type": "string",
      "description": "Identifier of the A-User session."
    },
    "AUCBKNID": {
      "type": "string",
      "description": "Identifier of this Request or Response."
    },
    "AUCBKNTime": {
      "$ref": "https://schemas.mpai.community/OSD/V1.5/data/SimpleTime.json"
    },
    "RequestID": {
      "type": "string",
      "description": "Response only. ID of the Request this Response answers."
    },
    "Instruction": {
      "type": "string",
      "enum": [
        "PED",
        "GLA",
        "PKQ",
        "GII",
        "PRF",
        "PCE",
        "CME",
        "AFR"
      ],
      "description": "Request only. The Instruction under which AUC issues the Request."
    },
    "Exchange": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "Phase": {
          "type": "string",
          "enum": [
            "new",
            "continuation"
          ]
        },
        "ResponseID": {
          "type": "string",
          "description": "ID of the Response to which a continuation Request follows."
        }
      },
      "required": [
        "Phase"
      ],
      "description": "Request only."
    },
    "Storage": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "Write": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "Category": {
                "type": "string"
              },
              "Readers": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "Time": {
                "type": "string",
                "enum": [
                  "module",
                  "session",
                  "persistent"
                ]
              }
            },
            "required": [
              "Category"
            ]
          }
        },
        "Read": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "description": "Request only. What the AIM may write to and read from the Private Storage of the Module, under the rules set by AUC."
    },
    "ProcessActionOutcome": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "PAStatus": {
          "type": "string"
        },
        "Complements": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "Constraint": {
          "type": "string",
          "description": "Resulting constraint on the Goal."
        }
      },
      "description": "Request only. Outcome of a Process Action performed by AUC in the M-Instance, conveyed so that the AIM operates knowing the current M-Instance state."
    },
    "Outcome": {
      "type": "string",
      "enum": [
        "achieved",
        "achieved_differently",
        "not_achieved"
      ],
      "description": "Response only. The outcome reached."
    },
    "Reason": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "Code": {
          "type": "string",
          "enum": [
            "none",
            "ambiguity_unresolved",
            "partner_unavailable",
            "constraint_conflict",
            "insufficient_context",
            "deadline_exceeded",
            "not_permitted"
          ]
        },
        "Description": {
          "type": "string"
        }
      },
      "required": [
        "Code"
      ],
      "description": "Response only. Structured reason, required when Outcome is not 'achieved'."
    },
    "StorageOutcome": {
      "type": "array",
      "description": "Response only. Outcome of the writes instructed by the Request.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "Category": {
            "type": "string"
          },
          "Result": {
            "type": "string",
            "enum": [
              "written",
              "not_authorised",
              "not_attempted"
            ]
          }
        },
        "required": [
          "Category",
          "Result"
        ]
      }
    },
    "Goal": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "Objective": {
          "type": "string"
        },
        "Constraints": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "Objective"
      ],
      "description": "Request only. Binding as to the objective and the constraints."
    },
    "Correction": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "Proposal": {
          "type": "string"
        },
        "Weight": {
          "type": "string",
          "enum": [
            "low",
            "medium",
            "high"
          ]
        },
        "Rationale": {
          "type": "string"
        }
      },
      "required": [
        "Proposal",
        "Weight"
      ],
      "description": "Request only. A correction proposed by AUC. The AIM may adopt it, adopt it partially or decline it, and says so in the Response."
    },
    "Abandon": {
      "type": "array",
      "description": "Request only. Unmet needs that AUC asks BKN to stop pursuing.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "NeedID": {
            "type": "string"
          },
          "Rationale": {
            "type": "string"
          }
        },
        "required": [
          "NeedID"
        ]
      }
    },
    "Actions": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "Requirement": {
          "type": "string",
          "enum": [
            "required",
            "optional",
            "not_requested"
          ]
        },
        "Allowed": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "Authenticate",
              "Author",
              "Convert",
              "Discover",
              "Execute",
              "Hide",
              "Identify",
              "Interpret",
              "License",
              "MM-Add",
              "MM-Animate",
              "MM-Capture",
              "MM-Move",
              "MM-Send",
              "Modify",
              "MU-Actuate",
              "MU-Add",
              "MU-Animate",
              "MU-Move",
              "MU-Send",
              "Post",
              "Property Change",
              "Register",
              "Resolve",
              "Rights Change",
              "Transact",
              "UM-Actuate",
              "UM-Capture",
              "UM-Send",
              "Validate"
            ]
          },
          "description": "The Process Actions that may be proposed."
        },
        "MaxSteps": {
          "type": "integer",
          "minimum": 1
        },
        "Locations": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "M-Locations in which the Process Actions may be performed."
        },
        "RightsRefs": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Identifiers of the Rights that the A-User holds and may use."
        },
        "WalletLimit": {
          "type": "number",
          "minimum": 0
        },
        "Syntax": {
          "type": "string",
          "const": "MMM-TEC-V2.2",
          "description": "The Process Actions shall conform with the grammar of MMM-TEC V2.2."
        }
      },
      "required": [
        "Requirement"
      ],
      "description": "Request only. Whether Process Actions are to be proposed, which ones, and within which limits."
    },
    "GoalUnderstood": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "Objective": {
          "type": "string"
        },
        "Constraints": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "Objective"
      ],
      "description": "Response only. The goal as the AIM understood it."
    },
    "DeliberationState": {
      "type": "string",
      "enum": [
        "deliberating",
        "concluded",
        "blocked"
      ],
      "description": "Response only."
    },
    "Conclusion": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "Headline": {
          "type": "string"
        },
        "FinalResponseID": {
          "type": "string",
          "description": "Identifier of the Final Response (a Basic Text Object) sent to A-User Formation and to AUC."
        },
        "CorrectionResponse": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "Decision": {
              "type": "string",
              "enum": [
                "none",
                "adopted",
                "partial",
                "declined"
              ]
            },
            "Reason": {
              "type": "string"
            }
          },
          "required": [
            "Decision"
          ],
          "description": "Response only. Treatment of the Correction proposed by AUC."
        }
      },
      "description": "Response only. The conclusion reached by BKN."
    },
    "UnmetNeeds": {
      "type": "array",
      "description": "Response only.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "NeedID": {
            "type": "string"
          },
          "Description": {
            "type": "string"
          },
          "Partner": {
            "type": "string",
            "enum": [
              "PRC",
              "DAC",
              "USR",
              "PAL",
              "none"
            ]
          },
          "SurfacedCount": {
            "type": "integer",
            "minimum": 1
          },
          "DeliberationStartTime": {
            "$ref": "https://schemas.mpai.community/OSD/V1.5/data/SimpleTime.json"
          }
        },
        "required": [
          "NeedID",
          "Description",
          "SurfacedCount",
          "DeliberationStartTime"
        ]
      }
    },
    "ActionsOutcome": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "Outcome": {
          "type": "string",
          "enum": [
            "produced",
            "partial",
            "failed",
            "not_requested"
          ]
        },
        "ProposedActionsID": {
          "type": "string",
          "description": "Identifier of the Process Action sequence sent on the output Port of the AIM."
        },
        "StepCount": {
          "type": "integer",
          "minimum": 0
        },
        "Reasons": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "Reason": {
                "type": "string",
                "enum": [
                  "none",
                  "ambiguity_unresolved",
                  "partner_unavailable",
                  "constraint_conflict",
                  "insufficient_context",
                  "deadline_exceeded",
                  "not_permitted"
                ]
              },
              "Description": {
                "type": "string"
              }
            },
            "required": [
              "Reason"
            ]
          }
        }
      },
      "required": [
        "Outcome"
      ],
      "description": "Response only. Outcome of the proposal of Process Actions."
    },
    "DataXMData": {
      "$ref": "https://schemas.mpai.community/PTF/V1.0/data/DataExchangeMetadata.json"
    },
    "DescrMetadata": {
      "type": "string",
      "maxLength": 2048
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "Mode": {
            "const": "RQ"
          }
        }
      },
      "then": {
        "required": [
          "Instruction",
          "Exchange",
          "Goal"
        ],
        "properties": {
          "RequestID": false,
          "Outcome": false,
          "Reason": false,
          "StorageOutcome": false,
          "GoalUnderstood": false,
          "DeliberationState": false,
          "Conclusion": false,
          "UnmetNeeds": false,
          "ActionsOutcome": false
        }
      }
    },
    {
      "if": {
        "properties": {
          "Mode": {
            "const": "RS"
          }
        }
      },
      "then": {
        "required": [
          "RequestID",
          "Outcome",
          "GoalUnderstood",
          "DeliberationState"
        ],
        "properties": {
          "Instruction": false,
          "Exchange": false,
          "Storage": false,
          "ProcessActionOutcome": false,
          "Goal": false,
          "Correction": false,
          "Abandon": false,
          "Actions": false
        }
      }
    },
    {
      "if": {
        "properties": {
          "Mode": {
            "const": "RS"
          },
          "Outcome": {
            "enum": [
              "achieved_differently",
              "not_achieved"
            ]
          }
        },
        "required": [
          "Mode",
          "Outcome"
        ]
      },
      "then": {
        "required": [
          "Reason"
        ]
      }
    }
  ]
}
