{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://altheia.local/schemas/altheia_product_ownership_policy_1.0.schema.json",
  "title": "altheia_product_ownership_policy_1.0 candidate — lot B",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "policy_id",
    "policy_version",
    "catalog_reference",
    "generation_mode",
    "offers",
    "relationship_rules",
    "provenance"
  ],
  "properties": {
    "schema_version": {
      "const": "altheia_product_ownership_policy_1.0"
    },
    "policy_id": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:_[a-z0-9]+)*$"
    },
    "policy_version": {
      "type": "string",
      "pattern": "^\\d+\\.\\d+\\.\\d+$"
    },
    "catalog_reference": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "sector_id",
        "catalog_id",
        "catalog_version",
        "catalog_hash"
      ],
      "properties": {
        "sector_id": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:_[a-z0-9]+)*$"
        },
        "catalog_id": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:_[a-z0-9]+)*$"
        },
        "catalog_version": {
          "type": "string",
          "pattern": "^\\d+\\.\\d+\\.\\d+$"
        },
        "catalog_hash": {
          "type": "string",
          "pattern": "^fnv1a-[a-f0-9]{8}$"
        }
      }
    },
    "generation_mode": {
      "enum": [
        "preserve_existing",
        "probabilistic",
        "quota"
      ]
    },
    "offers": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "offer_id",
          "allowed_provider_scopes",
          "target_rate",
          "target_count",
          "eligible_relationship_statuses",
          "requires_offers",
          "excludes_offers",
          "legacy_projection"
        ],
        "properties": {
          "offer_id": {
            "type": "string",
            "pattern": "^[a-z0-9]+(?:_[a-z0-9]+)*$"
          },
          "allowed_provider_scopes": {
            "type": "array",
            "minItems": 1,
            "items": {
              "enum": [
                "focal",
                "other",
                "unknown"
              ]
            },
            "uniqueItems": true
          },
          "target_rate": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0,
            "maximum": 1
          },
          "target_count": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          },
          "eligible_relationship_statuses": {
            "type": "array",
            "minItems": 0,
            "items": {
              "type": "string",
              "pattern": "^[a-z0-9]+(?:_[a-z0-9]+)*$"
            },
            "uniqueItems": true
          },
          "requires_offers": {
            "type": "array",
            "minItems": 0,
            "items": {
              "type": "string",
              "pattern": "^[a-z0-9]+(?:_[a-z0-9]+)*$"
            },
            "uniqueItems": true
          },
          "excludes_offers": {
            "type": "array",
            "minItems": 0,
            "items": {
              "type": "string",
              "pattern": "^[a-z0-9]+(?:_[a-z0-9]+)*$"
            },
            "uniqueItems": true
          },
          "legacy_projection": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "kind",
              "field",
              "code"
            ],
            "properties": {
              "kind": {
                "enum": [
                  "boolean",
                  "array",
                  "none"
                ]
              },
              "field": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "code": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          }
        }
      },
      "uniqueItems": true
    },
    "relationship_rules": {
      "type": "array",
      "minItems": 0,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "source_status",
          "minimum_total_products",
          "minimum_focal_products",
          "maximum_total_products"
        ],
        "properties": {
          "source_status": {
            "type": "string",
            "pattern": "^[a-z0-9]+(?:_[a-z0-9]+)*$"
          },
          "minimum_total_products": {
            "type": "integer",
            "minimum": 0
          },
          "minimum_focal_products": {
            "type": "integer",
            "minimum": 0
          },
          "maximum_total_products": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          }
        }
      },
      "uniqueItems": true
    },
    "provenance": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "basis",
        "sources",
        "rationale",
        "approved_by",
        "approved_at"
      ],
      "properties": {
        "basis": {
          "enum": [
            "simulation_assumption",
            "reference_data",
            "preservation"
          ]
        },
        "sources": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "rationale": {
          "type": "string",
          "minLength": 20
        },
        "approved_by": {
          "type": "string",
          "minLength": 1
        },
        "approved_at": {
          "type": "string",
          "format": "date-time"
        }
      }
    }
  }
}
