{
  "type": "object",
  "additionalProperties": false,
  "required": [
    "format",
    "knowledge_version",
    "id",
    "title",
    "intent",
    "context_id",
    "status",
    "classification",
    "settings",
    "conditions",
    "checks",
    "unresolved",
    "sources",
    "execution",
    "knowledge_policy"
  ],
  "properties": {
    "format": {
      "const": "itb.strategy-card/0.5.0"
    },
    "knowledge_version": {
      "const": "0.5.0"
    },
    "id": {
      "type": "string",
      "minLength": 1
    },
    "title": {
      "type": "string",
      "minLength": 1
    },
    "intent": {
      "type": "string",
      "minLength": 1
    },
    "context_id": {
      "type": "string",
      "minLength": 1
    },
    "status": {
      "enum": [
        "needs_input",
        "complete_example",
        "complete_proposal"
      ]
    },
    "classification": {
      "enum": [
        "educational_example",
        "user_draft"
      ]
    },
    "settings": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/field"
      },
      "minItems": 1
    },
    "symbols": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 40
      },
      "minItems": 2,
      "maxItems": 600,
      "uniqueItems": true,
      "description": "A pair list exists only for a test over several pairs. One pair is an ordinary single-pair card: omit symbols entirely and set profile.multi_enabled to false."
    },
    "conditions": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/condition"
      },
      "minItems": 0
    },
    "checks": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "schema_observation_id",
        "history_verified",
        "backend_timezone_verified",
        "deployed_engine_verified"
      ],
      "properties": {
        "schema_observation_id": {
          "type": "string",
          "minLength": 1
        },
        "history_verified": {
          "const": false
        },
        "backend_timezone_verified": {
          "const": false
        },
        "deployed_engine_verified": {
          "const": false
        }
      }
    },
    "unresolved": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "minItems": 0
    },
    "sources": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "minItems": 1
    },
    "execution": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "backtest_executed",
        "live_trade_executed",
        "results"
      ],
      "properties": {
        "backtest_executed": {
          "const": false
        },
        "live_trade_executed": {
          "const": false
        },
        "results": {
          "type": "null"
        }
      }
    },
    "knowledge_policy": {
      "const": "itb-only/1"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "status": {
            "const": "complete_example"
          }
        }
      },
      "then": {
        "properties": {
          "classification": {
            "const": "educational_example"
          },
          "settings": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "value": {
                  "not": {
                    "type": "null"
                  }
                },
                "origin": {
                  "not": {
                    "const": "unknown"
                  }
                }
              }
            }
          },
          "conditions": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "fields": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "value": {
                        "not": {
                          "type": "null"
                        }
                      },
                      "origin": {
                        "not": {
                          "const": "unknown"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "status": {
            "const": "complete_proposal"
          }
        }
      },
      "then": {
        "properties": {
          "classification": {
            "const": "user_draft"
          },
          "settings": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "value": {
                  "not": {
                    "type": "null"
                  }
                },
                "origin": {
                  "not": {
                    "const": "unknown"
                  }
                }
              },
              "allOf": [
                {
                  "if": {
                    "properties": {
                      "field_id": {
                        "enum": [
                          "backtest.symbol",
                          "backtest.start_dt",
                          "backtest.end_dt",
                          "backtest.initial_quote_qty",
                          "backtest.first_order",
                          "backtest.leverage"
                        ]
                      }
                    }
                  },
                  "then": {
                    "properties": {
                      "origin": {
                        "const": "user"
                      }
                    }
                  }
                }
              ]
            }
          },
          "conditions": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "fields": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "value": {
                        "not": {
                          "type": "null"
                        }
                      },
                      "origin": {
                        "not": {
                          "const": "unknown"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  ],
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "urn:itb:knowledge:strategy-card:0.5.0",
  "title": "ITradingBot corpus-only card: educational example or user proposal; no execution",
  "definitions": {
    "field": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "field_id",
        "value",
        "origin",
        "note"
      ],
      "properties": {
        "field_id": {
          "type": "string",
          "minLength": 1
        },
        "value": {
          "type": [
            "string",
            "number",
            "boolean",
            "null"
          ]
        },
        "origin": {
          "enum": [
            "user",
            "illustrative",
            "derived",
            "schema_default",
            "unknown",
            "agent_choice"
          ]
        },
        "note": {
          "type": "string"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "origin": {
                "const": "unknown"
              }
            }
          },
          "then": {
            "properties": {
              "value": {
                "type": "null"
              },
              "note": {
                "type": "string",
                "minLength": 1
              }
            }
          },
          "else": {
            "properties": {
              "value": {
                "not": {
                  "type": "null"
                }
              }
            }
          }
        }
      ]
    },
    "condition": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "definition_id",
        "role",
        "fields",
        "explanation"
      ],
      "properties": {
        "definition_id": {
          "type": "string",
          "minLength": 1
        },
        "role": {
          "enum": [
            "entry",
            "filter",
            "exit"
          ]
        },
        "fields": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/field"
          },
          "minItems": 1
        },
        "explanation": {
          "type": "string",
          "minLength": 1
        }
      }
    }
  }
}
