{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://dealeragentprotocol.com/spec/v0.1/schemas/dealer.schema.json",
  "title": "Dealer Agent Protocol dealer organization",
  "$defs": {
    "dealerRequest": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "organization_id": { "$ref": "common.schema.json#/$defs/identifier" },
        "rooftop_ids": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": { "$ref": "common.schema.json#/$defs/identifier" }
        }
      }
    },
    "contactPoint": {
      "type": "object",
      "additionalProperties": false,
      "required": ["department", "channel", "value"],
      "properties": {
        "department": {
          "type": "string",
          "enum": ["sales", "internet_sales", "service", "parts", "general"]
        },
        "channel": { "type": "string", "enum": ["phone", "email", "web"] },
        "value": { "type": "string", "minLength": 1, "maxLength": 320 },
        "public": { "type": "boolean" }
      }
    },
    "hoursInterval": {
      "type": "object",
      "additionalProperties": false,
      "required": ["day", "opens", "closes"],
      "properties": {
        "day": { "type": "string", "enum": ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"] },
        "opens": { "type": "string", "pattern": "^([01][0-9]|2[0-3]):[0-5][0-9]$" },
        "closes": { "type": "string", "pattern": "^([01][0-9]|2[0-3]):[0-5][0-9]$" }
      }
    },
    "rooftop": {
      "type": "object",
      "additionalProperties": false,
      "required": ["rooftop_id", "name", "address", "timezone", "departments"],
      "properties": {
        "rooftop_id": { "$ref": "common.schema.json#/$defs/identifier" },
        "name": { "type": "string", "minLength": 1, "maxLength": 200 },
        "legal_name": { "type": "string", "minLength": 1, "maxLength": 240 },
        "website": { "type": "string", "format": "uri" },
        "address": { "$ref": "common.schema.json#/$defs/address" },
        "timezone": { "type": "string", "minLength": 1, "maxLength": 64 },
        "departments": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": { "type": "string", "enum": ["sales", "internet_sales", "service", "parts"] }
        },
        "contacts": { "type": "array", "items": { "$ref": "#/$defs/contactPoint" } },
        "hours": { "type": "array", "items": { "$ref": "#/$defs/hoursInterval" } },
        "supported_languages": {
          "type": "array",
          "uniqueItems": true,
          "items": { "type": "string", "pattern": "^[a-z]{2,3}(?:-[A-Z]{2})?$" }
        },
        "supported_currencies": {
          "type": "array",
          "uniqueItems": true,
          "items": { "$ref": "common.schema.json#/$defs/currency" }
        },
        "extensions": { "$ref": "common.schema.json#/$defs/extensionBag" }
      }
    },
    "dealerOrganization": {
      "type": "object",
      "additionalProperties": false,
      "required": ["organization_id", "name", "rooftops", "provenance", "freshness"],
      "properties": {
        "organization_id": { "$ref": "common.schema.json#/$defs/identifier" },
        "name": { "type": "string", "minLength": 1, "maxLength": 200 },
        "legal_name": { "type": "string", "minLength": 1, "maxLength": 240 },
        "rooftops": {
          "type": "array",
          "minItems": 1,
          "items": { "$ref": "#/$defs/rooftop" }
        },
        "provenance": { "$ref": "common.schema.json#/$defs/provenance" },
        "freshness": { "$ref": "common.schema.json#/$defs/freshness" },
        "extensions": { "$ref": "common.schema.json#/$defs/extensionBag" }
      }
    }
  },
  "$ref": "#/$defs/dealerOrganization"
}
