{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.horusbi.com.br/schemas/v2/schedule.schema.json",
  "title": "Lumo v2 schedule YAML",
  "type": "object",
  "required": [
    "header",
    "body"
  ],
  "properties": {
    "fileName": {
      "$ref": "shared.schema.json#/$defs/resourceFileName"
    },
    "header": {
      "allOf": [
        {
          "$ref": "shared.schema.json#/$defs/resourceHeaderBase"
        },
        {
          "type": "object",
          "required": [
            "id"
          ],
          "properties": {
            "kind": {
              "const": "schedule"
            }
          }
        }
      ]
    },
    "body": {
      "allOf": [
        {
          "$ref": "shared.schema.json#/$defs/auditFields"
        },
        {
          "type": "object",
          "required": [
            "nome",
            "ativo",
            "timezone",
            "flows",
            "triggers"
          ],
          "properties": {
            "nome": {
              "type": "string",
              "minLength": 1
            },
            "ativo": {
              "type": "boolean"
            },
            "timezone": {
              "type": "string",
              "minLength": 1,
              "description": "IANA timezone name, required to avoid UTC/local ambiguity."
            },
            "version": {
              "$ref": "shared.schema.json#/$defs/readOnlyVersion"
            },
            "flows": {
              "type": "array",
              "items": {
                "type": "object",
                "required": [
                  "flow_etl_id",
                  "context"
                ],
                "properties": {
                  "flow_etl_id": {
                    "$ref": "shared.schema.json#/$defs/id"
                  },
                  "context": {
                    "$ref": "shared.schema.json#/$defs/loadContext"
                  }
                },
                "additionalProperties": true
              }
            },
            "triggers": {
              "type": "array",
              "items": {
                "oneOf": [
                  {
                    "description": "Hour or Minute interval - runs every N hours/minutes within a daily window. Minute is only allowed when the tenant config has schedulingGranularity='minutes'.",
                    "type": "object",
                    "required": [
                      "type",
                      "period",
                      "start_when",
                      "start_time",
                      "end_time"
                    ],
                    "properties": {
                      "type": {
                        "enum": [
                          "Hour",
                          "Minute"
                        ]
                      },
                      "period": {
                        "type": "integer",
                        "minimum": 1
                      },
                      "start_when": {
                        "$ref": "shared.schema.json#/$defs/isoDateTime"
                      },
                      "start_time": {
                        "$ref": "shared.schema.json#/$defs/localizedTime"
                      },
                      "end_time": {
                        "$ref": "shared.schema.json#/$defs/localizedTime"
                      }
                    },
                    "additionalProperties": true
                  },
                  {
                    "description": "Daily trigger - runs once per day at the given HH:MM (start_when carries only the time-of-day).",
                    "type": "object",
                    "required": [
                      "type",
                      "start_when"
                    ],
                    "properties": {
                      "type": {
                        "const": "Day"
                      },
                      "start_when": {
                        "type": "string",
                        "pattern": "^([01]?[0-9]|2[0-3]):[0-5][0-9]$",
                        "description": "HH:MM time-of-day. The backend stores it on today's date and re-synthesizes on each read."
                      }
                    },
                    "additionalProperties": true
                  },
                  {
                    "description": "Monthly trigger - runs on day-of-month (period 1-31) at HH:MM. Day 31 is clamped to last valid day on shorter months.",
                    "type": "object",
                    "required": [
                      "type",
                      "period",
                      "start_when"
                    ],
                    "properties": {
                      "type": {
                        "const": "Month"
                      },
                      "period": {
                        "type": "integer",
                        "minimum": 1,
                        "maximum": 31,
                        "description": "Day of month (treated as day-of-month, not interval count)."
                      },
                      "start_when": {
                        "type": "string",
                        "pattern": "^([01]?[0-9]|2[0-3]):[0-5][0-9]$",
                        "description": "HH:MM time-of-day."
                      }
                    },
                    "additionalProperties": true
                  },
                  {
                    "description": "Weekly trigger - runs on a day-of-week (period 0=Sun..6=Sat) at HH:MM. The backend encodes the day-of-week into the stored timestamp's date.",
                    "type": "object",
                    "required": [
                      "type",
                      "period",
                      "start_when"
                    ],
                    "properties": {
                      "type": {
                        "const": "Week"
                      },
                      "period": {
                        "type": "integer",
                        "minimum": 0,
                        "maximum": 6,
                        "description": "Day of week: 0=Sunday … 6=Saturday."
                      },
                      "start_when": {
                        "type": "string",
                        "pattern": "^([01]?[0-9]|2[0-3]):[0-5][0-9]$",
                        "description": "HH:MM time-of-day."
                      }
                    },
                    "additionalProperties": true
                  }
                ]
              }
            },
            "tags": {
              "$ref": "shared.schema.json#/$defs/tagList"
            }
          },
          "additionalProperties": true
        }
      ]
    }
  },
  "additionalProperties": false
}
