{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://valinweb.fr/docs/qr-render-request.schema.json",
  "title": "Valinweb QR render request",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "type",
    "payload"
  ],
  "properties": {
    "schemaVersion": {
      "type": "integer",
      "const": 1
    },
    "type": {
      "type": "string",
      "enum": [
        "url",
        "text",
        "email",
        "phone",
        "sms",
        "wifi",
        "contact"
      ]
    },
    "payload": {
      "type": "object"
    },
    "save": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "requestId"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100,
          "pattern": "\\S"
        },
        "requestId": {
          "type": "string",
          "pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"
        },
        "mode": {
          "type": "string",
          "enum": [
            "static",
            "dynamic"
          ],
          "default": "static"
        }
      }
    },
    "options": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "size": {
          "type": "string",
          "pattern": "^(?:12[89]|1[3-9][0-9]|[2-9][0-9]{2}|10[01][0-9]|102[0-4])$",
          "description": "Largeur et hauteur de l’image carrée en pixels. La signature valinweb.fr occupe une fine bande réservée sous le motif, à l’intérieur de ces dimensions."
        },
        "color": {
          "default": "#000000",
          "type": "string",
          "pattern": "^#[a-fA-F0-9]{6}$"
        },
        "bgColor": {
          "default": "#ffffff",
          "type": "string",
          "pattern": "^#[a-fA-F0-9]{6}$"
        },
        "correction": {
          "default": "M",
          "type": "string",
          "enum": [
            "L",
            "M",
            "Q",
            "H"
          ]
        },
        "margin": {
          "default": 2,
          "type": "integer",
          "minimum": 0,
          "maximum": 8
        }
      }
    },
    "format": {
      "type": "string",
      "enum": [
        "png",
        "svg"
      ]
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "type": {
            "const": "url"
          }
        },
        "required": [
          "type"
        ]
      },
      "then": {
        "properties": {
          "payload": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "url": {
                "type": "string",
                "maxLength": 4096,
                "minLength": 1,
                "pattern": "^(?:$|https?://[^\\s]+)$"
              }
            },
            "required": [
              "url"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "text"
          }
        },
        "required": [
          "type"
        ]
      },
      "then": {
        "properties": {
          "payload": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "text": {
                "type": "string",
                "maxLength": 4096,
                "minLength": 1
              }
            },
            "required": [
              "text"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "email"
          }
        },
        "required": [
          "type"
        ]
      },
      "then": {
        "properties": {
          "payload": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "receiver": {
                "type": "string",
                "maxLength": 4096,
                "minLength": 1,
                "pattern": "^(?:$|[^\\s@<>]+@[^\\s@<>]+\\.[^\\s@<>]+)$"
              },
              "subject": {
                "type": "string",
                "maxLength": 4096,
                "minLength": 1
              },
              "message": {
                "type": "string",
                "maxLength": 4096,
                "minLength": 1
              }
            },
            "required": [
              "receiver",
              "subject",
              "message"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "phone"
          }
        },
        "required": [
          "type"
        ]
      },
      "then": {
        "properties": {
          "payload": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "phone": {
                "type": "string",
                "maxLength": 4096,
                "minLength": 1
              }
            },
            "required": [
              "phone"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "sms"
          }
        },
        "required": [
          "type"
        ]
      },
      "then": {
        "properties": {
          "payload": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "phone": {
                "type": "string",
                "maxLength": 4096,
                "minLength": 1
              },
              "message": {
                "type": "string",
                "maxLength": 4096,
                "minLength": 1
              }
            },
            "required": [
              "phone",
              "message"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "wifi"
          }
        },
        "required": [
          "type"
        ]
      },
      "then": {
        "properties": {
          "payload": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "ssid": {
                "type": "string",
                "maxLength": 4096,
                "minLength": 1
              },
              "security": {
                "type": "string",
                "maxLength": 4096,
                "minLength": 1,
                "enum": [
                  "WPA",
                  "WEP",
                  "nopass"
                ]
              },
              "password": {
                "type": "string",
                "maxLength": 4096
              }
            },
            "required": [
              "ssid",
              "security"
            ],
            "allOf": [
              {
                "if": {
                  "properties": {
                    "security": {
                      "enum": [
                        "WPA",
                        "WEP"
                      ]
                    }
                  },
                  "required": [
                    "security"
                  ]
                },
                "then": {
                  "properties": {
                    "password": {
                      "type": "string",
                      "minLength": 1
                    }
                  },
                  "required": [
                    "password"
                  ]
                }
              }
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "type": {
            "const": "contact"
          }
        },
        "required": [
          "type"
        ]
      },
      "then": {
        "properties": {
          "payload": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "name": {
                "type": "string",
                "maxLength": 4096,
                "minLength": 1,
                "pattern": "^[^\\r\\n]*$"
              },
              "organization": {
                "type": "string",
                "maxLength": 4096,
                "pattern": "^[^\\r\\n]*$"
              },
              "phone": {
                "type": "string",
                "maxLength": 4096,
                "pattern": "^[^\\r\\n]*$"
              },
              "email": {
                "type": "string",
                "maxLength": 4096,
                "pattern": "^(?:$|[^\\s@<>]+@[^\\s@<>]+\\.[^\\s@<>]+)$"
              },
              "website": {
                "type": "string",
                "maxLength": 4096,
                "pattern": "^(?:$|https?://[^\\s]+)$"
              }
            },
            "required": [
              "name"
            ]
          }
        }
      }
    }
  ]
}
