{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "imports-v2/custom_properties.json",
  "title": "Custom properties",
  "description": "A custom property is an extra field that cards can carry, such as Priority, Target or Go-live date. One record holds the whole definition: the name, the type and, for a select property, the list of options users pick from.\n\n`type` decides how the property behaves and which extra settings it needs: `options` for `select` and `multi_select`, `vote_variant` with `data` for `vote`, and `directory_ref` for `directory`. The value a card has is not here but in the `properties` of `cards`, keyed by the `external_id` of the property; the files of an `attachment` property are `attachments` with `property_ref`. Without `space_refs` the property is available in all spaces; `show_on_facade` puts the value on the card face.\n\nA select property with two options. The options come in the order users see them:\n\n```json\n{\n  \"external_id\": \"cp-priority\",\n  \"name\": \"Priority\",\n  \"type\": \"select\",\n  \"options\": [\n    { \"external_id\": \"sv-high\", \"value\": \"High\", \"color\": \"#e53935\" },\n    { \"external_id\": \"sv-low\", \"value\": \"Low\" }\n  ]\n}\n```\n\nA card picks an option by its `external_id` in its `properties` (only that field of the card is shown):\n\n```json\n{\n  \"external_id\": \"k-mrr\",\n  \"properties\": { \"cp-priority\": \"sv-high\" }\n}\n```",
  "type": "object",
  "properties": {
    "external_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 512,
      "description": "Your own identifier of the record, for example `k-mrr`, unique within the resource across all of its files and case sensitive. Other records refer to this one by it. The import also keeps it as the external id of the object it creates."
    },
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 255,
      "description": "Name of the property as users see it, for example `Priority`. Up to 255 characters."
    },
    "type": {
      "type": "string",
      "enum": [
        "attachment",
        "checkbox",
        "date",
        "directory",
        "email",
        "multi_select",
        "multi_user",
        "multiline_string",
        "number",
        "phone",
        "select",
        "string",
        "url",
        "user",
        "vote"
      ],
      "description": "What the property holds: `attachment`, `checkbox`, `date`, `directory`, `email`, `multi_select`, `multi_user`, `multiline_string`, `number`, `phone`, `select`, `string`, `url`, `user` or `vote`."
    },
    "options": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "external_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 512,
            "description": "Your own identifier of the option, for example `sv-priority-high`, unique among the options of all properties of the package and case sensitive. Cards and directory records name the option by it. The import also keeps it as the external id of the option it creates."
          },
          "value": {
            "type": "string",
            "minLength": 1,
            "maxLength": 512,
            "description": "What users see for the option, for example `High`. Values are distinct within the property without regard to case."
          },
          "color": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^#[0-9A-Fa-f]{6}$",
            "x-palette": "option_colors",
            "description": "Color of the option as `#RRGGBB`, for example `#e53935`; the nearest color of the app's palette is used. The option is shown in this color in the property's list of options and on cards. Left out or null, the option has no color."
          },
          "condition": {
            "type": "string",
            "enum": [
              "active",
              "inactive"
            ],
            "default": "active",
            "description": "Whether the option is in use: `active` (the default) or `inactive`. An inactive option is listed apart, among the deactivated options of the property, and is not offered when users fill in the field on a card."
          }
        },
        "required": [
          "external_id",
          "value"
        ],
        "additionalProperties": false
      },
      "x-identity": "custom_properties.options",
      "description": "For a `select` or `multi_select` property, the options users can pick, in the order they are listed: the first item is the first option in the property's list of options and in the list users pick from on a card. Not allowed for other types. Left out, the property has no options."
    },
    "show_on_facade": {
      "type": "boolean",
      "description": "Whether the value is also shown on the card itself on the board, not only when the card is opened.",
      "default": false
    },
    "values_creatable_by_users": {
      "type": "boolean",
      "description": "For `select` and `multi_select`: whether users may add a new option while filling in the field on a card. Otherwise they pick only from the existing options.",
      "default": false
    },
    "vote_variant": {
      "type": "string",
      "enum": [
        "rating",
        "emoji_set"
      ],
      "description": "For a `vote` property, how users vote: `rating` (from 1 up to a number of points shown as emojis, like 4 of 5 stars) or `emoji_set` (one emoji out of a set). It decides the shape of `data`. Required for `vote` and not allowed for other types.",
      "x-required-when": "type is vote"
    },
    "data": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "count": {
              "type": "integer",
              "minimum": 2,
              "maximum": 10,
              "description": "How many points the rating has, from 2 to 10, for example `5`. The card shows this many emojis, and a user rates by clicking one of them: the third gives 3."
            },
            "emoji": {
              "type": "string",
              "minLength": 1,
              "description": "Emoji that stands for one rating point."
            }
          },
          "required": [
            "count",
            "emoji"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "emojis": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              },
              "uniqueItems": true,
              "minItems": 2,
              "maxItems": 10,
              "description": "Emojis a voter can choose from, 2 to 10 different ones."
            }
          },
          "required": [
            "emojis"
          ],
          "additionalProperties": false
        }
      ],
      "description": "For a `vote` property, the settings of its `vote_variant`. For `rating`, the number of points and the emoji of one point, for example `{\"count\": 5, \"emoji\": \"⭐\"}`. For `emoji_set`, the emojis to choose from, for example `{\"emojis\": [\"👍\", \"👎\"]}`. Required for `vote` and not allowed for other types.",
      "x-required-when": "type is vote"
    },
    "directory_ref": {
      "type": "string",
      "minLength": 1,
      "maxLength": 512,
      "x-ref": "custom_directories",
      "description": "For a `directory` property, the directory whose rows users pick as the value, by the external_id of a `custom_directories` record. Required for `directory` and not allowed for other types.",
      "x-required-when": "type is directory"
    },
    "space_refs": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 512,
        "x-ref": "spaces"
      },
      "uniqueItems": true,
      "minItems": 1,
      "description": "The spaces where the property can be added to cards, including everything inside them, by the external_id of `spaces` records. Leave it out to make the property available everywhere. Cards that already have a value keep showing it."
    },
    "condition": {
      "type": "string",
      "enum": [
        "active",
        "inactive"
      ],
      "description": "Whether the property is in use: `active` (the default) or `inactive`. An inactive property can't be added to cards, and the values cards already have stay visible but can't be edited.",
      "default": "active"
    },
    "author_ref": {
      "type": [
        "string",
        "null"
      ],
      "minLength": 1,
      "maxLength": 512,
      "x-ref": "users",
      "description": "The user who created the property, shown in the Author column of the list of properties, by the external_id of a `users` record, for example `u-ava`. Left out or null, the author is the user who runs the import."
    }
  },
  "required": [
    "external_id",
    "name",
    "type"
  ],
  "additionalProperties": false,
  "allOf": [
    {
      "if": {
        "properties": {
          "type": {
            "enum": [
              "vote"
            ]
          }
        },
        "required": [
          "type"
        ]
      },
      "then": {
        "required": [
          "vote_variant"
        ]
      },
      "else": {
        "not": {
          "required": [
            "vote_variant"
          ]
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "enum": [
              "vote"
            ]
          }
        },
        "required": [
          "type"
        ]
      },
      "then": {
        "required": [
          "data"
        ]
      },
      "else": {
        "not": {
          "required": [
            "data"
          ]
        }
      }
    },
    {
      "allOf": [
        {
          "if": {
            "required": [
              "vote_variant"
            ],
            "properties": {
              "vote_variant": {
                "enum": [
                  "rating"
                ]
              }
            }
          },
          "then": {
            "properties": {
              "data": {
                "required": [
                  "count",
                  "emoji"
                ]
              }
            }
          }
        },
        {
          "if": {
            "required": [
              "vote_variant"
            ],
            "properties": {
              "vote_variant": {
                "enum": [
                  "emoji_set"
                ]
              }
            }
          },
          "then": {
            "properties": {
              "data": {
                "required": [
                  "emojis"
                ]
              }
            }
          }
        }
      ]
    },
    {
      "if": {
        "properties": {
          "type": {
            "enum": [
              "select",
              "multi_select"
            ]
          }
        },
        "required": [
          "type"
        ]
      },
      "else": {
        "not": {
          "required": [
            "options"
          ]
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "enum": [
              "directory"
            ]
          }
        },
        "required": [
          "type"
        ]
      },
      "then": {
        "required": [
          "directory_ref"
        ]
      },
      "else": {
        "not": {
          "required": [
            "directory_ref"
          ]
        }
      }
    }
  ]
}
