{ "$schema":              "https://json-schema.org/draft/2020-12/schema",
  "$id":                  "https://schemas.mpai.community/OSD/V1.5/data/RRULE.json",
  "title":                "RRULE V1.5", 
  "description":          "JSON representation & validation of iCalendar RFC 5545 recurrence rule (RRULE).",
  "type":                 "object", 
  "additionalProperties": false, 
  "required":             ["freq"], 
  "properties":           {

    "freq":               { "type": "string", "description": "Frequency of recurrence as defined by RFC 5545.",
                            "enum": ["SECONDLY","MINUTELY","HOURLY","DAILY","WEEKLY","MONTHLY","YEARLY"] },

    "interval":           { "type": "integer", "minimum": 1, "default": 1,
                            "description": "Intervening interval between events for the given FREQ." },

    "until":              { "description": "End date/time of recurrence. UNTIL or COUNT may appear, but not both.", "anyOf": [
                          { "$ref": "https://schemas.mpai.community/OSD/V1.5/data/SpaceTime.json" },
                          { "type": "string", "pattern": "^[0-9]{8}T[0-9]{6}Z$" } ] },
                          
    "count":              { "type": "integer", "minimum": 1,
                            "description": "Number of occurrences. COUNT or UNTIL may appear, but not both." },

    "bysecond":           { "type": "array", "uniqueItems": true, "minItems": 1, "description": "Seconds within the minute (0–59).",
                            "items": { "type": "integer", "minimum": 0, "maximum": 59 } },

    "byminute":           { "type": "array", "uniqueItems": true, "minItems": 1, "description": "Minutes within the hour (0–59).",
                            "items": { "type": "integer", "minimum": 0, "maximum": 59 } },

    "byhour":             { "type": "array", "uniqueItems": true, "minItems": 1, "description": "Hours of the day (0–23).",
                            "items": { "type": "integer", "minimum": 0, "maximum": 23 } },

    "byday":              { "type": "array", "uniqueItems": true, "minItems": 1, 
                            "description": "Weekdays, optionally with ordinal (e.g., 1MO, -1SU).",
                            "items": { "type": "string", "anyOf": [
                          { "pattern": "^(MO|TU|WE|TH|FR|SA|SU)$" },
                          { "pattern": "^([+-]?(?:[1-9]|[1-4][0-9]|5[0-3]))(MO|TU|WE|TH|FR|SA|SU)$" } ] } },

    "bymonthday":         { "type": "array", "uniqueItems": true, "minItems": 1, "description": "Days of the month: -31..-1 or 1..31.",
                            "items": { "type": "integer", "oneOf": [
                          { "minimum": 1,  "maximum": 31 },
                          { "minimum": -31, "maximum": -1 } ] } },

    "byyearday":          { "type": "array", "uniqueItems": true, "minItems": 1, "description": "Days of the year: -366..-1 or 1..366.",
                            "items": { "type": "integer", "oneOf": [
                          { "minimum": 1,   "maximum": 366 },
                          { "minimum": -366, "maximum": -1 } ] } },

    "byweekno":           { "type": "array", "uniqueItems": true, "minItems": 1, 
                            "description": "Week numbers of the year: -53..-1 or 1..53.", "items": { "type": "integer", "oneOf": [
                          { "minimum": 1,  "maximum": 53 },
                          { "minimum": -53, "maximum": -1 } ] } },

    "bymonth":            { "type": "array", "uniqueItems": true, "minItems": 1, "description": "Months of the year (1–12).",
                            "items": { "type": "integer", "minimum": 1, "maximum": 12 } },

    "bysetpos":           { "type": "array", "uniqueItems": true, "minItems": 1,
                            "description": "Positions within the result set (-366..-1 or 1..366).", "items": { "type": "integer", "oneOf": [
                          { "minimum": 1,   "maximum": 366 },
                          { "minimum": -366, "maximum": -1 } ] } },

    "wkst":               { "type": "string", "description": "Week start day (default MO).",
                            "enum": ["MO","TU","WE","TH","FR","SA","SU"], "default": "MO" },

    "DataXMData":         { "$ref": "https://schemas.mpai.community/PTF/V1.0/data/DataExchangeMetadata.json" },
    "DescrMetadata":      { "type": "string", "maxLength": 2048 } } }