{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://aisalabs.dev/schemas/brief.schema.json",
  "title": "Website Brief",
  "type": "object",
  "required": ["brief_version", "site_type", "common", "contacts", "structure"],
  "additionalProperties": false,
  "properties": {
    "brief_version": { "type": "string", "const": "1.0" },
    "site_type": {
      "type": "string",
      "enum": ["local_business", "personal_brand", "agency"]
    },
    "common": {
      "type": "object",
      "required": ["business_name", "business_type", "description", "language"],
      "additionalProperties": false,
      "properties": {
        "business_name": { "type": "string", "minLength": 1 },
        "business_type": { "type": "string", "minLength": 1 },
        "description": { "type": "string", "minLength": 1 },
        "language": { "type": "string", "pattern": "^[a-z]{2}(-[A-Z]{2})?$" },
        "tone": { "type": "string", "enum": ["professional", "friendly", "premium"] }
      }
    },
    "contacts": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "phone": { "type": "string", "minLength": 1 },
        "email": { "type": "string", "format": "email" },
        "whatsapp": { "type": "string", "minLength": 1 },
        "address": { "type": "string", "minLength": 1 },
        "city": { "type": "string", "minLength": 1 },
        "region": { "type": "string", "minLength": 1 }
      },
      "anyOf": [
        { "required": ["phone"] },
        { "required": ["email"] },
        { "required": ["whatsapp"] }
      ]
    },
    "services": {
      "type": "object",
      "required": ["items"],
      "additionalProperties": false,
      "properties": {
        "items": {
          "type": "array",
          "minItems": 1,
          "maxItems": 6,
          "items": {
            "type": "object",
            "required": ["title"],
            "additionalProperties": false,
            "properties": {
              "title": { "type": "string", "minLength": 1 },
              "description": { "type": "string" }
            }
          }
        }
      }
    },
    "hours": {
      "type": "object",
      "required": ["schedule"],
      "additionalProperties": false,
      "properties": {
        "schedule": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": ["day", "open", "close"],
            "additionalProperties": false,
            "properties": {
              "day": {
                "type": "string",
                "enum": ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]
              },
              "open": {
                "type": "string",
                "pattern": "^([01][0-9]|2[0-3]):[0-5][0-9]$"
              },
              "close": {
                "type": "string",
                "pattern": "^([01][0-9]|2[0-3]):[0-5][0-9]$"
              }
            }
          }
        }
      }
    },
    "media": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "logo": { "type": "string", "minLength": 1 },
        "hero_image": { "type": "string", "minLength": 1 },
        "gallery": {
          "type": "array",
          "minItems": 1,
          "maxItems": 12,
          "items": { "type": "string", "minLength": 1 }
        }
      }
    },
    "structure": {
      "type": "object",
      "required": ["sections", "primary_cta"],
      "additionalProperties": false,
      "properties": {
        "sections": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "enum": [
              "hero", "services", "about", "hours",
              "gallery", "testimonials", "faq", "contact", "footer"
            ]
          }
        },
        "primary_cta": {
          "type": "string",
          "enum": ["form", "phone", "whatsapp", "email"]
        }
      }
    },
    "style": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "palette_hint": {
          "type": "string",
          "enum": ["warm", "cool", "neutral", "bold"]
        }
      }
    },
    "functional": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "modules": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string",
            "enum": ["form_capture", "whatsapp", "cookie_consent", "map"]
          }
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "required": ["structure"],
        "properties": {
          "structure": {
            "required": ["primary_cta"],
            "properties": { "primary_cta": { "const": "phone" } }
          }
        }
      },
      "then": {
        "required": ["contacts"],
        "properties": { "contacts": { "required": ["phone"] } }
      }
    },
    {
      "if": {
        "required": ["structure"],
        "properties": {
          "structure": {
            "required": ["primary_cta"],
            "properties": { "primary_cta": { "const": "email" } }
          }
        }
      },
      "then": {
        "required": ["contacts"],
        "properties": { "contacts": { "required": ["email"] } }
      }
    },
    {
      "if": {
        "required": ["structure"],
        "properties": {
          "structure": {
            "required": ["primary_cta"],
            "properties": { "primary_cta": { "const": "whatsapp" } }
          }
        }
      },
      "then": {
        "required": ["contacts"],
        "properties": { "contacts": { "required": ["whatsapp"] } }
      }
    },
    {
      "if": {
        "required": ["structure"],
        "properties": {
          "structure": {
            "required": ["primary_cta"],
            "properties": { "primary_cta": { "const": "form" } }
          }
        }
      },
      "then": {
        "required": ["functional"],
        "properties": {
          "functional": {
            "required": ["modules"],
            "properties": {
              "modules": { "contains": { "const": "form_capture" } }
            }
          }
        }
      }
    },
    {
      "if": {
        "required": ["site_type"],
        "properties": { "site_type": { "const": "local_business" } }
      },
      "then": {
        "required": ["contacts"],
        "properties": {
          "contacts": { "required": ["address", "city"] }
        }
      }
    },
    {
      "if": {
        "required": ["structure"],
        "properties": {
          "structure": {
            "required": ["sections"],
            "properties": {
              "sections": { "contains": { "const": "services" } }
            }
          }
        }
      },
      "then": { "required": ["services"] }
    },
    {
      "if": {
        "required": ["structure"],
        "properties": {
          "structure": {
            "required": ["sections"],
            "properties": {
              "sections": { "contains": { "const": "hours" } }
            }
          }
        }
      },
      "then": { "required": ["hours"] }
    },
    {
      "if": {
        "required": ["structure"],
        "properties": {
          "structure": {
            "required": ["sections"],
            "properties": {
              "sections": { "contains": { "const": "gallery" } }
            }
          }
        }
      },
      "then": {
        "required": ["media"],
        "properties": { "media": { "required": ["gallery"] } }
      }
    }
  ]
}