{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schema.mp.microsoft.com/schema/private-offer-mpo-originator/2023-07-15",
  "title": "Microsoft Product Ingestion MultiParty Private Offer",
  "description": "Describes a MultiParty Private Offer in the Microsoft Product Ingestion API",
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "pattern": "^[^\\!\\\u003C\\\u003E\\^\\[\\]\\@\\#\\%\\/\\x00-\\x1F\\x7E-\\xFF]\u002B$",
      "maxLength": 128
    },
    "privateOfferType": {
      "type": "string",
      "const": "multipartyPromotionOriginator"
    },
    "upgradedFrom": {
      "$ref": "https://schema.mp.microsoft.com/schema/private-offer-promotion-reference/2022-07-01"
    },
    "variableStartDate": {
      "type": "boolean"
    },
    "start": {
      "type": "string",
      "format": "date"
    },
    "end": {
      "type": "string",
      "format": "date"
    },
    "acceptBy": {
      "type": "string",
      "format": "date"
    },
    "notificationContacts": {
      "type": "array",
      "maxItems": 5,
      "items": {
        "type": "string",
        "format": "email"
      }
    },
    "state": {
      "type": "string",
      "enum": [
        "draft",
        "live",
        "deleted"
      ]
    },
    "subState": {
      "type": "string",
      "enum": [
        "pendingPartnerAction",
        "pendingAcceptance",
        "accepted"
      ]
    },
    "termsAndConditionsDocs": {
      "type": "array",
      "maxItems": 5,
      "items": {
        "$ref": "https://schema.mp.microsoft.com/schema/private-offer-terms-doc/2023-07-15"
      }
    },
    "beneficiaries": {
      "type": "array",
      "maxItems": 1,
      "items": {
        "$ref": "https://schema.mp.microsoft.com/schema/private-offer-beneficiary/2022-07-01",
        "properties": {
          "beneficiaryRecipients": {
            "items": {
              "properties": {
                "recipientType": {
                  "const": "billingGroup"
                }
              }
            }
          }
        }
      }
    },
    "partners": {
      "type": "array",
      "maxItems": 1,
      "items": {
        "$ref": "https://schema.mp.microsoft.com/schema/private-offer-partner/2023-07-15",
        "required": [
          "id"
        ]
      }
    },
    "pricing": {
      "type": "array",
      "items": {
        "$ref": "https://schema.mp.microsoft.com/schema/private-offer-pricing/2023-07-15",
        "not": {
          "required": [
            "markupPercentage"
          ]
        }
      }
    },
    "lastModified": {
      "type": "string",
      "format": "date"
    },
    "notes": {
      "type": "string",
      "pattern": "^[^\\!\\\u003C\\\u003E\\^\\[\\]\\@\\#\\%\\/\\x00-\\x1F\\x7E-\\xFF]\u002B$",
      "maxLength": 60
    },
    "eTag": {
      "type": "string"
    }
  },
  "required": [
    "state"
  ],
  "allOf": [
    {
      "if": {
        "required": [
          "start"
        ]
      },
      "then": {
        "properties": {
          "variableStartDate": {
            "not": {
              "const": true
            }
          }
        }
      }
    },
    {
      "if": {
        "not": {
          "properties": {
            "variableStartDate": {
              "const": true
            }
          }
        }
      },
      "then": {
        "required": [
          "start"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "state": {
            "const": "live"
          }
        },
        "not": {
          "required": [
            "upgradedFrom"
          ]
        }
      },
      "then": {
        "properties": {
          "beneficiaries": {
            "minItems": 1
          },
          "pricing": {
            "minItems": 1
          },
          "partners": {
            "minItems": 1
          }
        },
        "required": [
          "end",
          "acceptBy",
          "beneficiaries",
          "pricing",
          "name"
        ]
      }
    }
  ],
  "$defs": {
    "https://schema.mp.microsoft.com/schema/private-offer-promotion-reference/2022-07-01": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://schema.mp.microsoft.com/schema/private-offer-promotion-reference/2022-07-01",
      "title": "Microsoft Product Ingestion Private Offer Promotion Reference",
      "description": "Describes a promotion reference for a Private Offer in the Microsoft Product Ingestion API",
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        }
      },
      "required": [
        "id",
        "name"
      ]
    },
    "https://schema.mp.microsoft.com/schema/private-offer-terms-doc/2023-07-15": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://schema.mp.microsoft.com/schema/private-offer-terms-doc/2023-07-15",
      "title": "Microsoft Product Ingestion Private Offer Terms Document",
      "description": "Describes a Terms and Conditions Document for a Private Offer in the Microsoft Product Ingestion API",
      "type": "object",
      "properties": {
        "fileName": {
          "type": "string",
          "pattern": "^[\\x20-\\x7F]\u002B[^\\!\\\u003E\\^\\[\\\u003E\\!\\@\\#\\%\\/\\]]$",
          "maxLength": 128
        },
        "customerFacingDocumentName": {
          "type": "string",
          "pattern": "^[\\x20-\\x7F]\u002B[^\\!\\\u003E\\^\\[\\\u003E\\!\\@\\#\\%\\/\\]]$",
          "maxLength": 100
        },
        "sasUrl": {
          "type": "string",
          "format": "uri"
        }
      },
      "required": [
        "fileName",
        "customerFacingDocumentName",
        "sasUrl"
      ]
    },
    "https://schema.mp.microsoft.com/schema/private-offer-beneficiary/2022-07-01": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://schema.mp.microsoft.com/schema/private-offer-beneficiary/2022-07-01",
      "title": "Microsoft Product Ingestion Private Offer Beneficiary",
      "description": "Describes a Beneficiary for a Private Offer in the Microsoft Product Ingestion API",
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "beneficiaryRecipients": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/beneficiaryRecipient"
          }
        }
      },
      "required": [
        "id"
      ]
    },
    "https://schema.mp.microsoft.com/schema/private-offer-partner/2023-07-15": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://schema.mp.microsoft.com/schema/private-offer-partner/2023-07-15",
      "title": "Microsoft Product Ingestion Private Offer Partner",
      "description": "Describes a partner for a Private Offer in the Microsoft Product Ingestion API",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string"
        },
        "partnerName": {
          "type": "string"
        },
        "location": {
          "type": "string"
        }
      }
    },
    "https://schema.mp.microsoft.com/schema/private-offer-pricing/2023-07-15": {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://schema.mp.microsoft.com/schema/private-offer-pricing/2023-07-15",
      "title": "Microsoft Product Ingestion Private Offer Pricing Configuration",
      "description": "Describes the pricing for a private offer in the Microsoft Product Ingestion API",
      "type": "object",
      "oneOf": [
        {
          "additionalProperties": false,
          "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"
            },
            "discountType": {
              "type": "string",
              "enum": [
                "percentage",
                "absolute"
              ],
              "default": "percentage"
            },
            "discountPercentage": {
              "type": "number",
              "minimum": 0.01,
              "maximum": 100,
              "multipleOf": 0.01
            },
            "markupPercentage": {
              "type": "number",
              "minimum": 0.00000001,
              "maximum": 100,
              "multipleOf": 0.00000001
            },
            "planName": {
              "type": "string"
            },
            "productName": {
              "type": "string"
            },
            "priceDetails": {
              "$ref": "https://schema.mp.microsoft.com/schema/resource-reference/2022-07-01"
            }
          },
          "required": [
            "product",
            "discountType"
          ],
          "allOf": [
            {
              "if": {
                "properties": {
                  "discountType": {
                    "const": "absolute"
                  }
                }
              },
              "then": {
                "allOf": [
                  {
                    "required": [
                      "plan",
                      "priceDetails"
                    ]
                  },
                  {
                    "not": {
                      "required": [
                        "discountPercentage"
                      ]
                    }
                  }
                ]
              }
            },
            {
              "if": {
                "properties": {
                  "discountType": {
                    "const": "percentage"
                  }
                }
              },
              "then": {
                "allOf": [
                  {
                    "required": [
                      "discountPercentage"
                    ]
                  },
                  {
                    "not": {
                      "required": [
                        "priceDetails"
                      ]
                    }
                  }
                ]
              }
            }
          ]
        },
        {
          "additionalProperties": false,
          "properties": {
            "product": {
              "$ref": "https://schema.mp.microsoft.com/schema/resource-reference/2022-07-01"
            },
            "basePlan": {
              "$ref": "https://schema.mp.microsoft.com/schema/resource-reference/2022-07-01"
            },
            "newPlanDetails": {
              "properties": {
                "name": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                },
                "id": {
                  "type": "string"
                }
              }
            },
            "discountType": {
              "const": "absolute"
            },
            "markupPercentage": {
              "type": "number",
              "minimum": 0.00000001,
              "maximum": 100,
              "multipleOf": 0.00000001
            },
            "basePlanName": {
              "type": "string"
            },
            "productName": {
              "type": "string"
            },
            "priceDetails": {
              "$ref": "https://schema.mp.microsoft.com/schema/resource-reference/2022-07-01"
            }
          },
          "required": [
            "product",
            "basePlan",
            "discountType",
            "priceDetails"
          ]
        }
      ]
    },
    "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/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-])*$"
    },
    "beneficiaryRecipient": {
      "required": [
        "id",
        "recipientType"
      ],
      "id": {
        "type": "string"
      },
      "recipientType": {
        "enum": [
          "cspCustomer"
        ]
      }
    }
  }
}