{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://api-evangelist.github.io/allegion/json-schema/schlage-home-access-code-schema.json",
  "title": "Schlage Home Access Code",
  "description": "A numeric access code stored on a Schlage Home device with a schedule that may be Always, Temporary, or Recurring.",
  "type": "object",
  "required": ["accessCodeId", "name", "code", "schedule"],
  "properties": {
    "accessCodeId": { "type": "string" },
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 12,
      "pattern": "^[a-zA-Z0-9]+$",
      "description": "1-12 character alpha-numeric label. Updating the name does not change the numeric access code."
    },
    "code": {
      "type": "string",
      "pattern": "^[0-9]+$",
      "description": "Numeric access code. Per-device length is changed by deleting all codes."
    },
    "accessorType": {
      "type": "string",
      "description": "Accessor classification (e.g. Owner, Guest). New accessor types were added March 25, 2025."
    },
    "schedule": {
      "oneOf": [
        {
          "type": "object",
          "required": ["type"],
          "properties": {
            "type": { "const": "Always" }
          }
        },
        {
          "type": "object",
          "required": ["type", "startDateTime", "endDateTime"],
          "properties": {
            "type": { "const": "Temporary" },
            "startDateTime": {
              "type": "string",
              "format": "date-time",
              "description": "Includes DST offset since April 14, 2026."
            },
            "endDateTime": {
              "type": "string",
              "format": "date-time"
            }
          }
        },
        {
          "type": "object",
          "required": ["type", "daysOfWeek", "startTime", "endTime"],
          "properties": {
            "type": { "const": "Recurring" },
            "daysOfWeek": {
              "type": "array",
              "items": {
                "type": "string",
                "enum": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
              }
            },
            "startTime": { "type": "string", "pattern": "^([01][0-9]|2[0-3]):[0-5][0-9]$" },
            "endTime": { "type": "string", "pattern": "^([01][0-9]|2[0-3]):[0-5][0-9]$" }
          }
        }
      ]
    }
  }
}
