{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://oods-foundry.com/schemas/brand.intake.input.json",
  "title": "brand_create input",
  "description": "brand_create input: create, draft, apply.",
  "type": "object",
  "required": [
    "action"
  ],
  "properties": {
    "action": {
      "type": "string",
      "enum": [
        "create",
        "draft",
        "apply"
      ],
      "description": "Choose create, draft, apply."
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "action": {
            "type": "string",
            "const": "create"
          }
        },
        "required": [
          "action"
        ]
      },
      "then": {
        "type": "object",
        "properties": {
          "action": {
            "type": "string",
            "const": "create"
          },
          "brand_id": {
            "type": "string",
            "minLength": 1,
            "description": "The id the brand will have. Checked when given: capitals then digits (ACME, A1) or a letter then lower-case letters and digits (Acme, acme2), at most 32 characters, and no existing brand's id in any case."
          },
          "documents": {
            "type": "object",
            "description": "The filled template: one plain design-token document per theme, brand-relative (surface.canvas, not color.brand.<id>.surface.canvas), each slot {\"$type\": \"color\", \"$value\": \"<CSS colour>\"}.",
            "properties": {
              "base": {
                "type": "object",
                "description": "The light theme."
              },
              "dark": {
                "type": "object",
                "description": "The dark theme."
              },
              "hc": {
                "type": "object",
                "description": "The high-contrast theme."
              }
            },
            "additionalProperties": false
          },
          "recipe": {
            "$ref": "#/$defs/recipe",
            "description": "A brand recipe in place of documents: the brand it gives is checked, and for create written, like filled documents."
          }
        },
        "required": [
          "brand_id"
        ],
        "oneOf": [
          {
            "required": [
              "documents"
            ]
          },
          {
            "required": [
              "recipe"
            ]
          }
        ],
        "additionalProperties": false
      }
    },
    {
      "if": {
        "properties": {
          "action": {
            "type": "string",
            "const": "draft"
          }
        },
        "required": [
          "action"
        ]
      },
      "then": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "action": {
            "type": "string",
            "const": "draft"
          },
          "brand_id": {
            "type": "string",
            "minLength": 1
          },
          "source": {
            "type": "object",
            "properties": {
              "path": {
                "type": "string",
                "pattern": "^/[\\s\\S]*$"
              },
              "modes": {
                "type": "object",
                "properties": {
                  "base": {
                    "type": "string"
                  },
                  "dark": {
                    "type": "string"
                  }
                },
                "additionalProperties": false
              }
            },
            "required": [
              "path"
            ],
            "additionalProperties": false
          },
          "bindings": {
            "type": "object",
            "properties": {
              "base": {
                "type": "object",
                "additionalProperties": {
                  "type": "string"
                }
              },
              "dark": {
                "type": "object",
                "additionalProperties": {
                  "type": "string"
                }
              }
            },
            "additionalProperties": false
          },
          "from": {
            "type": "object",
            "properties": {
              "brand": {
                "type": "string",
                "format": "oods-brand"
              },
              "preset": {
                "type": "string"
              }
            },
            "additionalProperties": false
          }
        },
        "required": [
          "source",
          "brand_id"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "action": {
            "type": "string",
            "const": "apply"
          }
        },
        "required": [
          "action"
        ]
      },
      "then": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "action": {
            "type": "string",
            "const": "apply"
          },
          "draftId": {
            "type": "string",
            "pattern": "^brand-[a-f0-9]{64}$"
          },
          "accept": {
            "type": "boolean",
            "const": true
          }
        },
        "required": [
          "draftId",
          "accept"
        ]
      }
    }
  ],
  "$defs": {
    "recipe": {
      "type": "object",
      "description": "A brand recipe: the neutral (a hue and a tint of 0 to 0.03), the accent hue, whether the primary action is the neutral (near-black in light, near-white in dark) or the accent, the control radius in px, and the sans family. Every colour, the radius set and the font stacks follow from it, graded like any brand.",
      "required": [
        "neutralHue",
        "neutralChroma",
        "accentHue",
        "primary",
        "radius",
        "font"
      ],
      "additionalProperties": false,
      "properties": {
        "neutralHue": {
          "type": "number",
          "minimum": 0,
          "maximum": 360
        },
        "neutralChroma": {
          "type": "number",
          "minimum": 0,
          "maximum": 0.03
        },
        "accentHue": {
          "type": "number",
          "minimum": 0,
          "maximum": 360
        },
        "primary": {
          "type": "string",
          "enum": [
            "neutral",
            "accent"
          ]
        },
        "radius": {
          "type": "number",
          "minimum": 0,
          "maximum": 16
        },
        "font": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64
        },
        "fontMono": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64
        },
        "status": {
          "type": "object",
          "description": "Status hues, each { hue, chroma? }: info, success, warning, critical, archive.",
          "additionalProperties": {
            "type": "object",
            "required": [
              "hue"
            ],
            "additionalProperties": false,
            "properties": {
              "hue": {
                "type": "number",
                "minimum": 0,
                "maximum": 360
              },
              "chroma": {
                "type": "number",
                "minimum": 0,
                "maximum": 1.5
              }
            }
          }
        }
      }
    }
  }
}
