{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/nice/json-schema/nice-policy-creation-request-schema.json",
  "title": "PolicyCreationRequest",
  "x-generated": "2026-11-11",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/nice-policy-policyinstance-openapi.yml#/components/schemas/PolicyCreationRequest",
  "required": [
    "entityType",
    "policyName",
    "policyType",
    "criteria"
  ],
  "type": "object",
  "properties": {
    "policyName": {
      "type": "string",
      "description": "The name of the policy. Policy name should not be more than 120 characters & cannot contain /!\\+<>?#|:*&,%"
    },
    "policyType": {
      "type": "string",
      "description": "Type of the policy"
    },
    "entityType": {
      "pattern": "MASTER_CONTACT|SEGMENT",
      "type": "string",
      "description": "Entity type associated with the policy",
      "enum": [
        "MASTER_CONTACT",
        "SEGMENT"
      ]
    },
    "description": {
      "type": "string",
      "description": "Description of the policy. Policy description should not be more than 500 characters & cannot contain cannot contain /!\\+<>?#|:*&,%"
    },
    "criteria": {
      "type": "array",
      "description": "Criteria for filtering policy records",
      "items": {
        "$ref": "#/$defs/Criteria"
      }
    },
    "recurring": {
      "type": "boolean",
      "description": "Indicates if policy is recurring"
    },
    "recurrenceConfig": {
      "$ref": "#/$defs/RecurrenceConfig"
    },
    "retentionValueInDays": {
      "type": "string",
      "description": "Specifies the retention period for media, in days. This field is required and applies only to the Retention Change policy. Valid values are between 0 and 9999, or 'Indefinite'."
    },
    "applyToMediaTypes": {
      "pattern": "VOICE|SCREEN",
      "type": "string",
      "description": "Specifies the entity type associated with the policy. This field is required only for the Retention Change policy.",
      "enum": [
        "VOICE",
        "SCREEN"
      ]
    }
  },
  "$defs": {
    "Criteria": {
      "type": "object",
      "properties": {
        "fieldId": {
          "type": "string",
          "description": "Unique identifier for the filtering field"
        },
        "operator": {
          "type": "string",
          "description": "Comparison operator for the filtering condition"
        },
        "range": {
          "$ref": "#/$defs/Range"
        },
        "value": {
          "type": "string",
          "description": "Single value for filtering when using EQ operator"
        },
        "values": {
          "type": "array",
          "description": "List of values for filtering when using IN operator",
          "items": {
            "type": "string",
            "description": "List of values for filtering when using IN operator"
          }
        }
      },
      "description": "Criteria for filtering records"
    },
    "Range": {
      "type": "object",
      "properties": {
        "from": {
          "type": "string"
        },
        "to": {
          "type": "string"
        }
      },
      "description": "Range of values when using BETWEEN operator"
    },
    "RecurrenceConfig": {
      "type": "object",
      "properties": {
        "frequency": {
          "pattern": "DAILY|WEEKLY|MONTHLY",
          "type": "string",
          "description": "Frequency of recurrence",
          "enum": [
            "DAILY",
            "WEEKLY",
            "MONTHLY"
          ]
        },
        "recurrenceEndType": {
          "pattern": "DATE|NO_OF_OCCURRENCES|NEVER",
          "type": "string",
          "description": "End type of recurrence",
          "enum": [
            "DATE",
            "NO_OF_OCCURRENCES",
            "NEVER"
          ]
        },
        "recurrenceEndDate": {
          "type": "string",
          "description": "End date of recurrence (if recurrenceEndType:DATE)"
        },
        "totalNoOfRecurrences": {
          "type": "integer",
          "description": "Total number of recurrences (if recurrenceEndType: NO_OF_OCCURRENCES )",
          "format": "int32"
        },
        "dayOfWeek": {
          "pattern": "MONDAY|TUESDAY|WEDNESDAY|THURSDAY|FRIDAY|SATURDAY|SUNDAY",
          "type": "string",
          "description": "Applicable day of the week for recurrence",
          "enum": [
            "MONDAY",
            "TUESDAY",
            "WEDNESDAY",
            "THURSDAY",
            "FRIDAY",
            "SATURDAY",
            "SUNDAY"
          ]
        },
        "dayOfMonth": {
          "maximum": 28,
          "minimum": 1,
          "type": "integer",
          "description": "Applicable day of the month for recurrence",
          "format": "int32"
        }
      },
      "description": "Configuration for recurring policies"
    }
  }
}