{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.baijimu.com/contracts/timer-definition/1.0.0/schema.json",
  "title": "Baijimu Bundle Timer Definition",
  "description": "Authoring definition for one Bundle-owned Timer resource.",
  "type": "object",
  "additionalProperties": false,
  "required": ["name", "target", "schedule", "enabled"],
  "properties": {
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200,
      "pattern": "^\\S(?:[\\s\\S]*\\S)?$"
    },
    "description": {
      "type": ["string", "null"],
      "minLength": 1,
      "maxLength": 2000,
      "pattern": "^\\S(?:[\\s\\S]*\\S)?$"
    },
    "target": {
      "$ref": "#/$defs/target"
    },
    "schedule": {
      "oneOf": [
        { "$ref": "#/$defs/cronSchedule" },
        { "$ref": "#/$defs/everySchedule" },
        { "$ref": "#/$defs/atSchedule" }
      ]
    },
    "enabled": {
      "type": "boolean"
    }
  },
  "$defs": {
    "nonBlankText": {
      "type": "string",
      "minLength": 1,
      "pattern": "^\\S(?:[\\s\\S]*\\S)?$"
    },
    "target": {
      "type": "object",
      "additionalProperties": false,
      "required": ["businessId", "method"],
      "properties": {
        "businessId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200,
          "pattern": "^\\S(?:[\\s\\S]*\\S)?$"
        },
        "method": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100,
          "pattern": "^\\S(?:[\\s\\S]*\\S)?$"
        },
        "params": true
      }
    },
    "cronSchedule": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "expression", "timezone"],
      "properties": {
        "type": { "const": "CRON" },
        "expression": { "$ref": "#/$defs/nonBlankText" },
        "timezone": { "$ref": "#/$defs/nonBlankText" }
      }
    },
    "everySchedule": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "everyMs"],
      "properties": {
        "type": { "const": "EVERY" },
        "everyMs": {
          "type": "integer",
          "minimum": 300000
        }
      }
    },
    "atSchedule": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "at"],
      "properties": {
        "type": { "const": "AT" },
        "at": {
          "type": "string",
          "format": "date-time"
        }
      }
    }
  }
}
