{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schema.mp.microsoft.com/schema/price-and-availability-private-offer-plan/2022-07-01",
  "description": "PriceAndAvailability private offer plan level resource schema definition",
  "allOf": [
    {
      "$ref": "https://schema.mp.microsoft.com/schema/resource/2022-07-01"
    },
    {
      "title": "private offer plan",
      "type": "object",
      "required": [
        "product",
        "plan",
        "pricing"
      ],
      "properties": {
        "product": {
          "$ref": "https://schema.mp.microsoft.com/schema/resource-reference/2022-07-01"
        },
        "plan": {
          "$ref": "https://schema.mp.microsoft.com/schema/resource-reference/2022-07-01"
        },
        "pricing": {
          "$ref": "https://schema.mp.microsoft.com/schema/price-and-availability-private-offer-price/2022-07-01"
        }
      }
    }
  ],
  "$defs": {
    "https://schema.mp.microsoft.com/schema/resource/2022-07-01": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://schema.mp.microsoft.com/schema/resource/2022-07-01",
      "$comment": "This schema is extended by a resource type schema. We allow additional properties to enable that",
      "type": "object",
      "properties": {
        "resourceName": {
          "type": "string",
          "minLength": 1,
          "maxLength": 50
        },
        "id": {
          "$ref": "https://schema.mp.microsoft.com/schema/durable-id/2022-07-01"
        },
        "validations": {
          "type": "array",
          "items": {
            "$ref": "https://schema.mp.microsoft.com/schema/validation/2022-07-01"
          },
          "readonly": true
        }
      },
      "required": [
        "$schema"
      ],
      "additionalProperties": true
    },
    "https://schema.mp.microsoft.com/schema/resource-reference/2022-07-01": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://schema.mp.microsoft.com/schema/resource-reference/2022-07-01",
      "oneOf": [
        {
          "$ref": "https://schema.mp.microsoft.com/schema/durable-id/2022-07-01"
        },
        {
          "type": "object",
          "properties": {
            "externalId": {
              "description": "ExternalId for product and plan references. Property reference must be named product or plan.",
              "type": "string",
              "pattern": "^[a-z0-9][a-z0-9-_]{2,49}$",
              "minLength": 3,
              "maxLength": 50,
              "$example": {
                "plan": {
                  "externalId": "customerNamedPlan123"
                }
              }
            }
          },
          "required": [
            "externalId"
          ]
        },
        {
          "type": "object",
          "properties": {
            "resourceName": {
              "description": "Resource Name that can be referenced using this value by another resource.",
              "type": "string",
              "pattern": "^[a-zA-Z0-9-_]\u002B$",
              "minLength": 1,
              "maxLength": 50,
              "$example": {
                "plan": {
                  "resourceName": "resourcePlan1"
                }
              }
            }
          },
          "required": [
            "resourceName"
          ]
        }
      ]
    },
    "https://schema.mp.microsoft.com/schema/price-and-availability-private-offer-price/2022-07-01": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://schema.mp.microsoft.com/schema/price-and-availability-private-offer-price/2022-07-01",
      "description": "Absolute Pricing Configuration for Private Offers",
      "title": "private-offer-price",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "recurrentPrice": {
          "properties": {
            "priceInputOption": {
              "type": "string",
              "enum": [
                "perMarket",
                "usd"
              ],
              "default": "usd"
            },
            "prices": {
              "type": "array",
              "minItems": 1,
              "items": {
                "type": "object",
                "properties": {
                  "billingTerm": {
                    "properties": {
                      "type": {
                        "type": "string",
                        "enum": [
                          "month",
                          "year"
                        ],
                        "default": "month"
                      },
                      "value": {
                        "type": "number"
                      }
                    },
                    "required": [
                      "type",
                      "value"
                    ]
                  },
                  "paymentOption": {
                    "properties": {
                      "type": {
                        "type": "string",
                        "enum": [
                          "month",
                          "year"
                        ],
                        "default": "month"
                      },
                      "value": {
                        "type": "number"
                      }
                    },
                    "required": [
                      "type",
                      "value"
                    ]
                  },
                  "prices": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "markets": {
                          "$ref": "https://schema.mp.microsoft.com/schema/price-and-availability-market/2022-07-01"
                        },
                        "currency": {
                          "type": "string",
                          "pattern": "[a-z]{3}"
                        },
                        "price": {
                          "type": "number"
                        }
                      }
                    }
                  },
                  "pricePerPaymentInUsd": {
                    "type": "number"
                  }
                },
                "required": [
                  "billingTerm"
                ]
              }
            }
          },
          "allOf": [
            {
              "if": {
                "properties": {
                  "priceInputOption": {
                    "const": "perMarket"
                  }
                }
              },
              "then": {
                "properties": {
                  "prices": {
                    "items": {
                      "required": [
                        "prices"
                      ],
                      "not": {
                        "required": [
                          "pricePerPaymentInUsd"
                        ]
                      }
                    }
                  }
                }
              }
            },
            {
              "if": {
                "properties": {
                  "priceInputOption": {
                    "const": "usd"
                  }
                }
              },
              "then": {
                "properties": {
                  "prices": {
                    "items": {
                      "required": [
                        "pricePerPaymentInUsd"
                      ],
                      "not": {
                        "required": [
                          "prices"
                        ]
                      }
                    }
                  }
                }
              }
            }
          ],
          "required": [
            "priceInputOption",
            "prices"
          ]
        },
        "customMeters": {
          "properties": {
            "priceInputOption": {
              "type": "string",
              "enum": [
                "perMarket",
                "usd"
              ],
              "default": "usd"
            },
            "meters": {
              "type": "object"
            }
          },
          "required": [
            "priceInputOption",
            "meters"
          ],
          "allOf": [
            {
              "if": {
                "properties": {
                  "priceInputOption": {
                    "const": "usd"
                  }
                }
              },
              "then": {
                "properties": {
                  "meters": {
                    "additionalProperties": {
                      "type": "object",
                      "properties": {
                        "pricePerPaymentInUsd": {
                          "type": "number"
                        }
                      },
                      "required": [
                        "pricePerPaymentInUsd"
                      ]
                    }
                  }
                }
              }
            },
            {
              "if": {
                "properties": {
                  "priceInputOption": {
                    "const": "perMarket"
                  }
                }
              },
              "then": {
                "properties": {
                  "meters": {
                    "additionalProperties": {
                      "type": "array",
                      "items": {
                        "properties": {
                          "markets": {
                            "$ref": "https://schema.mp.microsoft.com/schema/price-and-availability-market/2022-07-01"
                          },
                          "currency": {
                            "type": "string",
                            "pattern": "[a-z]{3}"
                          },
                          "price": {
                            "type": "number"
                          }
                        },
                        "required": [
                          "markets",
                          "currency",
                          "price"
                        ]
                      }
                    }
                  }
                }
              }
            }
          ]
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "customMeters": {
                "not": {
                  "type": "null"
                },
                "properties": {
                  "priceInputOption": {
                    "const": "perMarket"
                  }
                }
              }
            },
            "required": [
              "customMeters"
            ]
          },
          "then": {
            "properties": {
              "recurrentPrice": {
                "properties": {
                  "priceInputOption": {
                    "const": "perMarket"
                  }
                }
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "customMeters": {
                "not": {
                  "type": "null"
                },
                "properties": {
                  "priceInputOption": {
                    "const": "usd"
                  }
                }
              }
            },
            "required": [
              "customMeters"
            ]
          },
          "then": {
            "properties": {
              "recurrentPrice": {
                "properties": {
                  "priceInputOption": {
                    "const": "usd"
                  }
                }
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "recurrentPrice": {
                "not": {
                  "type": "null"
                },
                "properties": {
                  "priceInputOption": {
                    "const": "usd"
                  }
                }
              }
            },
            "required": [
              "recurrentPrice"
            ]
          },
          "then": {
            "properties": {
              "customMeters": {
                "properties": {
                  "priceInputOption": {
                    "const": "usd"
                  }
                }
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "recurrentPrice": {
                "not": {
                  "type": "null"
                },
                "properties": {
                  "priceInputOption": {
                    "const": "perMarket"
                  }
                }
              }
            },
            "required": [
              "recurrentPrice"
            ]
          },
          "then": {
            "properties": {
              "customMeters": {
                "properties": {
                  "priceInputOption": {
                    "const": "perMarket"
                  }
                }
              }
            }
          }
        }
      ]
    },
    "https://schema.mp.microsoft.com/schema/durable-id/2022-07-01": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://schema.mp.microsoft.com/schema/durable-id/2022-07-01",
      "description": "A durable-id to an existing resource.",
      "type": "string",
      "pattern": "^[a-z](-?[a-z0-9]\u002B)*/[a-z0-9-]\u002B(\\/?[a-z0-9-])*$"
    },
    "https://schema.mp.microsoft.com/schema/validation/2022-07-01": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://schema.mp.microsoft.com/schema/validation/2022-07-01",
      "allOf": [
        {
          "$ref": "https://schema.mp.microsoft.com/schema/inner-error/2022-07-01"
        },
        {
          "properties": {
            "$schema": {
              "$ref": "https://schema.mp.microsoft.com/schema/schema-uri/2022-07-01"
            },
            "level": {
              "type": "string",
              "enum": [
                "informational",
                "warning"
              ]
            }
          },
          "required": [
            "level"
          ]
        }
      ]
    },
    "https://schema.mp.microsoft.com/schema/inner-error/2022-07-01": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://schema.mp.microsoft.com/schema/inner-error/2022-07-01",
      "type": "object",
      "properties": {
        "resourceId": {
          "$ref": "https://schema.mp.microsoft.com/schema/resource-reference/2022-07-01"
        },
        "code": {
          "type": "string",
          "readOnly": true,
          "enum": [
            "businessValidationError",
            "collectionLimitExceeded",
            "invalidId",
            "invalidEntityStatus",
            "invalidRequest",
            "invalidResource",
            "invalidState",
            "notDeployed",
            "notSupported",
            "operationCanceled",
            "productLocked",
            "resourceNotFound",
            "schemaValidationError"
          ]
        },
        "message": {
          "type": "string"
        },
        "details": {
          "type": "array",
          "items": {
            "$ref": "https://schema.mp.microsoft.com/schema/inner-error/2022-07-01"
          }
        }
      },
      "required": [
        "code"
      ]
    },
    "https://schema.mp.microsoft.com/schema/schema-uri/2022-07-01": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://schema.mp.microsoft.com/schema/schema-uri/2022-07-01",
      "title": "Product Ingestion schema uri",
      "type": "string",
      "pattern": "^https://schema\\.mp.microsoft\\.com/schema/[a-z][a-z0-9]\u002B(?:-[a-z0-9]\u002B)*/\\d{4}(?:-\\d\\d){2}(-preview\\d\u002B)?$"
    },
    "https://schema.mp.microsoft.com/schema/price-and-availability-market/2022-07-01": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://schema.mp.microsoft.com/schema/price-and-availability-market/2022-07-01",
      "description": "PriceAndAvailability audience definition",
      "title": "markets",
      "type": "array",
      "default": [],
      "items": {
        "type": "string",
        "pattern": "[a-z]{2,3}"
      }
    }
  }
}