{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/vicem-ai/json-schema/vicem-ai-save-rule-response-schema.json",
  "title": "SaveRuleResponse",
  "x-generated": "2026-11-28",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/vicem-ai-openapi.json#/components/schemas/SaveRuleResponse",
  "type": "object",
  "properties": {
    "savedId": {
      "type": "string",
      "maxLength": 140
    },
    "restore": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "away"
            },
            "until": {
              "$ref": "#/$defs/IsoDate"
            },
            "callerLine": {
              "default": null,
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 200
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "kind",
            "until",
            "callerLine"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "expecting"
            },
            "who": {
              "type": "string",
              "minLength": 1,
              "maxLength": 60
            },
            "number": {
              "default": null,
              "anyOf": [
                {
                  "$ref": "#/$defs/E164"
                },
                {
                  "type": "null"
                }
              ]
            },
            "contactId": {
              "default": null,
              "anyOf": [
                {
                  "$ref": "#/$defs/Id"
                },
                {
                  "type": "null"
                }
              ]
            },
            "until": {
              "$ref": "#/$defs/IsoDate"
            }
          },
          "required": [
            "kind",
            "who",
            "number",
            "contactId",
            "until"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "always_put_through"
            },
            "contactId": {
              "default": null,
              "anyOf": [
                {
                  "$ref": "#/$defs/Id"
                },
                {
                  "type": "null"
                }
              ]
            },
            "saysFrom": {
              "default": null,
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 60
                },
                {
                  "type": "null"
                }
              ]
            },
            "until": {
              "default": null,
              "anyOf": [
                {
                  "$ref": "#/$defs/IsoDate"
                },
                {
                  "type": "null"
                }
              ]
            },
            "newContact": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 60
                },
                "e164": {
                  "$ref": "#/$defs/E164"
                }
              },
              "required": [
                "name",
                "e164"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "kind",
            "contactId",
            "saysFrom",
            "until"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "caller_note"
            },
            "for": {
              "anyOf": [
                {
                  "type": "string",
                  "const": "everyone"
                },
                {
                  "$ref": "#/$defs/Id"
                },
                {
                  "minItems": 2,
                  "maxItems": 5,
                  "type": "array",
                  "items": {
                    "$ref": "#/$defs/Id"
                  }
                }
              ]
            },
            "text": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            },
            "until": {
              "default": null,
              "anyOf": [
                {
                  "$ref": "#/$defs/IsoDate"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "kind",
            "for",
            "text",
            "until"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "say_no"
            },
            "topic": {
              "type": "string",
              "minLength": 1,
              "maxLength": 60
            },
            "politeLine": {
              "type": "string",
              "minLength": 1,
              "maxLength": 120
            }
          },
          "required": [
            "kind",
            "topic",
            "politeLine"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "handling_note"
            },
            "text": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            },
            "until": {
              "default": null,
              "anyOf": [
                {
                  "$ref": "#/$defs/IsoDate"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "kind",
            "text",
            "until"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "booking_day"
            },
            "day": {
              "type": "integer",
              "minimum": 0,
              "maximum": 6
            },
            "allowed": {
              "type": "boolean",
              "const": false
            }
          },
          "required": [
            "kind",
            "day",
            "allowed"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "job_hunt"
            },
            "until": {
              "$ref": "#/$defs/IsoDate"
            },
            "roles": {
              "default": [],
              "maxItems": 3,
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1,
                "maxLength": 40
              }
            }
          },
          "required": [
            "kind",
            "until",
            "roles"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "job_hunt_end"
            }
          },
          "required": [
            "kind"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "remember"
            },
            "text": {
              "type": "string",
              "minLength": 1,
              "maxLength": 400
            }
          },
          "required": [
            "kind",
            "text"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "away_end"
            }
          },
          "required": [
            "kind"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "not_rule"
            },
            "reason": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            }
          },
          "required": [
            "kind",
            "reason"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "emergency_words"
            },
            "words": {
              "minItems": 1,
              "maxItems": 10,
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 2,
                "maxLength": 40
              }
            }
          },
          "required": [
            "kind",
            "words"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "day_off"
            },
            "date": {
              "type": "string",
              "pattern": "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])$"
            }
          },
          "required": [
            "kind",
            "date"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "closed_day"
            },
            "day": {
              "type": "integer",
              "minimum": 0,
              "maximum": 6
            }
          },
          "required": [
            "kind",
            "day"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "quiet_hours"
            },
            "start": {
              "type": "string",
              "pattern": "^(?:[01]\\d|2[0-3]):[0-5]\\d$"
            },
            "end": {
              "type": "string",
              "pattern": "^(?:[01]\\d|2[0-3]):[0-5]\\d$"
            },
            "urgentRings": {
              "default": null,
              "type": [
                "boolean",
                "null"
              ]
            },
            "days": {
              "minItems": 1,
              "maxItems": 7,
              "type": "array",
              "items": {
                "type": "integer",
                "minimum": 0,
                "maximum": 6
              }
            }
          },
          "required": [
            "kind",
            "start",
            "end",
            "urgentRings"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "ring_me"
            },
            "phone": {
              "default": null,
              "anyOf": [
                {
                  "$ref": "#/$defs/E164"
                },
                {
                  "type": "null"
                }
              ]
            }
          },
          "required": [
            "kind",
            "phone"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "unsupported"
            },
            "reason": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            },
            "link": {
              "type": "string",
              "pattern": "^\\/[a-z0-9/_?=&-]{0,120}$"
            }
          },
          "required": [
            "kind",
            "reason",
            "link"
          ],
          "additionalProperties": false
        }
      ]
    },
    "items": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 3,
            "maxLength": 140
          },
          "kind": {
            "type": "string",
            "enum": [
              "away",
              "expecting",
              "always_put_through",
              "caller_note",
              "say_no",
              "handling_note",
              "booking_day",
              "unsupported",
              "job_hunt",
              "job_hunt_end",
              "remember",
              "away_end",
              "not_rule",
              "emergency_words",
              "day_off",
              "closed_day",
              "quiet_hours",
              "ring_me"
            ]
          },
          "group": {
            "type": "string",
            "enum": [
              "everyone",
              "person",
              "says_no",
              "temporary"
            ]
          },
          "who": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "type": "string",
                    "const": "everyone"
                  }
                },
                "required": [
                  "kind"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "type": "string",
                    "const": "person"
                  },
                  "name": {
                    "type": "string",
                    "maxLength": 80
                  },
                  "contactId": {
                    "anyOf": [
                      {
                        "$ref": "#/$defs/Id"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                },
                "required": [
                  "kind",
                  "name",
                  "contactId"
                ],
                "additionalProperties": false
              }
            ]
          },
          "text": {
            "type": "string",
            "maxLength": 400
          },
          "line": {
            "type": "object",
            "properties": {
              "key": {
                "type": "string",
                "enum": [
                  "away",
                  "expecting",
                  "putThrough",
                  "saysFrom",
                  "note",
                  "sayNo",
                  "jobHunt",
                  "jobHuntEnd",
                  "jobHuntRow",
                  "tells",
                  "expectingRow",
                  "own",
                  "bookingDay",
                  "awayRow",
                  "cantDo",
                  "caseNotRule",
                  "nameWhoHears",
                  "remember",
                  "awayEnd",
                  "notRule",
                  "emergencyWords",
                  "dayOff",
                  "closedDay",
                  "quietHours",
                  "quietDays"
                ]
              },
              "arg": {
                "anyOf": [
                  {
                    "type": "string",
                    "maxLength": 400
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "day": {
                "type": "integer",
                "minimum": 0,
                "maximum": 6
              },
              "addFreeTimes": {
                "type": "boolean"
              },
              "words": {
                "maxItems": 10,
                "type": "array",
                "items": {
                  "type": "string",
                  "maxLength": 40
                }
              },
              "quiet": {
                "type": "object",
                "properties": {
                  "start": {
                    "type": "string",
                    "pattern": "^(?:[01]\\d|2[0-3]):[0-5]\\d$"
                  },
                  "end": {
                    "type": "string",
                    "pattern": "^(?:[01]\\d|2[0-3]):[0-5]\\d$"
                  },
                  "urgent": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "start",
                  "end",
                  "urgent"
                ],
                "additionalProperties": false
              },
              "days": {
                "maxItems": 7,
                "type": "array",
                "items": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 6
                }
              }
            },
            "required": [
              "key"
            ],
            "additionalProperties": false
          },
          "says": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 400
              },
              {
                "type": "null"
              }
            ]
          },
          "until": {
            "anyOf": [
              {
                "$ref": "#/$defs/IsoDate"
              },
              {
                "type": "null"
              }
            ]
          },
          "since": {
            "anyOf": [
              {
                "$ref": "#/$defs/IsoDate"
              },
              {
                "type": "null"
              }
            ]
          },
          "endable": {
            "type": "boolean"
          }
        },
        "required": [
          "id",
          "kind",
          "group",
          "who",
          "text",
          "says",
          "until",
          "since",
          "endable"
        ],
        "additionalProperties": false
      }
    },
    "active": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 3,
            "maxLength": 140
          },
          "kind": {
            "type": "string",
            "enum": [
              "away",
              "expecting",
              "always_put_through",
              "caller_note",
              "say_no",
              "handling_note",
              "booking_day",
              "unsupported",
              "job_hunt",
              "job_hunt_end",
              "remember",
              "away_end",
              "not_rule",
              "emergency_words",
              "day_off",
              "closed_day",
              "quiet_hours",
              "ring_me"
            ]
          },
          "group": {
            "type": "string",
            "enum": [
              "everyone",
              "person",
              "says_no",
              "temporary"
            ]
          },
          "who": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "type": "string",
                    "const": "everyone"
                  }
                },
                "required": [
                  "kind"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "type": "string",
                    "const": "person"
                  },
                  "name": {
                    "type": "string",
                    "maxLength": 80
                  },
                  "contactId": {
                    "anyOf": [
                      {
                        "$ref": "#/$defs/Id"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                },
                "required": [
                  "kind",
                  "name",
                  "contactId"
                ],
                "additionalProperties": false
              }
            ]
          },
          "text": {
            "type": "string",
            "maxLength": 400
          },
          "line": {
            "type": "object",
            "properties": {
              "key": {
                "type": "string",
                "enum": [
                  "away",
                  "expecting",
                  "putThrough",
                  "saysFrom",
                  "note",
                  "sayNo",
                  "jobHunt",
                  "jobHuntEnd",
                  "jobHuntRow",
                  "tells",
                  "expectingRow",
                  "own",
                  "bookingDay",
                  "awayRow",
                  "cantDo",
                  "caseNotRule",
                  "nameWhoHears",
                  "remember",
                  "awayEnd",
                  "notRule",
                  "emergencyWords",
                  "dayOff",
                  "closedDay",
                  "quietHours",
                  "quietDays"
                ]
              },
              "arg": {
                "anyOf": [
                  {
                    "type": "string",
                    "maxLength": 400
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "day": {
                "type": "integer",
                "minimum": 0,
                "maximum": 6
              },
              "addFreeTimes": {
                "type": "boolean"
              },
              "words": {
                "maxItems": 10,
                "type": "array",
                "items": {
                  "type": "string",
                  "maxLength": 40
                }
              },
              "quiet": {
                "type": "object",
                "properties": {
                  "start": {
                    "type": "string",
                    "pattern": "^(?:[01]\\d|2[0-3]):[0-5]\\d$"
                  },
                  "end": {
                    "type": "string",
                    "pattern": "^(?:[01]\\d|2[0-3]):[0-5]\\d$"
                  },
                  "urgent": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "start",
                  "end",
                  "urgent"
                ],
                "additionalProperties": false
              },
              "days": {
                "maxItems": 7,
                "type": "array",
                "items": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 6
                }
              }
            },
            "required": [
              "key"
            ],
            "additionalProperties": false
          },
          "says": {
            "anyOf": [
              {
                "type": "string",
                "maxLength": 400
              },
              {
                "type": "null"
              }
            ]
          },
          "until": {
            "anyOf": [
              {
                "$ref": "#/$defs/IsoDate"
              },
              {
                "type": "null"
              }
            ]
          },
          "since": {
            "anyOf": [
              {
                "$ref": "#/$defs/IsoDate"
              },
              {
                "type": "null"
              }
            ]
          },
          "endable": {
            "type": "boolean"
          }
        },
        "required": [
          "id",
          "kind",
          "group",
          "who",
          "text",
          "says",
          "until",
          "since",
          "endable"
        ],
        "additionalProperties": false
      }
    }
  },
  "required": [
    "items",
    "active"
  ],
  "additionalProperties": false,
  "$defs": {
    "E164": {
      "type": "string",
      "pattern": "^\\+[1-9]\\d{6,14}$"
    },
    "Id": {
      "type": "string",
      "minLength": 3,
      "maxLength": 64
    },
    "IsoDate": {
      "type": "string",
      "format": "date-time",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
    }
  }
}