{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://happydebits.com/ledger-action.schema.json",
  "title": "Happydebits ledger action proposal",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "version",
    "message",
    "clarifyingQuestion",
    "assumptions",
    "actions"
  ],
  "properties": {
    "version": { "const": 1 },
    "message": { "type": "string", "maxLength": 500 },
    "clarifyingQuestion": {
      "type": ["string", "null"],
      "maxLength": 500
    },
    "assumptions": {
      "type": "array",
      "maxItems": 12,
      "items": { "type": "string", "maxLength": 240 }
    },
    "actions": {
      "type": "array",
      "maxItems": 50,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "type",
          "targetId",
          "targetName",
          "subscription",
          "changes",
          "status",
          "confidence",
          "reason"
        ],
        "properties": {
          "type": {
            "enum": ["add", "update", "set_status", "delete"]
          },
          "targetId": { "type": ["string", "null"] },
          "targetName": { "type": ["string", "null"] },
          "subscription": {
            "anyOf": [
              { "$ref": "#/$defs/subscription" },
              { "type": "null" }
            ]
          },
          "changes": {
            "anyOf": [
              { "$ref": "#/$defs/changes" },
              { "type": "null" }
            ]
          },
          "status": {
            "anyOf": [
              { "enum": ["active", "paused", "cancelled"] },
              { "type": "null" }
            ]
          },
          "confidence": {
            "type": "number",
            "minimum": 0,
            "maximum": 1
          },
          "reason": { "type": "string", "maxLength": 240 }
        }
      }
    }
  },
  "$defs": {
    "subscription": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "amount",
        "currency",
        "interval",
        "category",
        "nextBillingDate",
        "status",
        "notes",
        "paymentMethod"
      ],
      "properties": {
        "name": { "type": "string" },
        "amount": { "type": "number", "minimum": 0 },
        "currency": {
          "enum": ["USD", "EUR", "GBP", "INR", "CAD", "AUD"]
        },
        "interval": {
          "enum": ["weekly", "monthly", "quarterly", "yearly"]
        },
        "category": {
          "enum": [
            "entertainment",
            "software",
            "utilities",
            "health",
            "news",
            "shopping",
            "finance",
            "other"
          ]
        },
        "nextBillingDate": { "type": ["string", "null"] },
        "status": { "enum": ["active", "paused", "cancelled"] },
        "notes": { "type": "string" },
        "paymentMethod": { "type": "string" }
      }
    },
    "changes": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "amount",
        "currency",
        "interval",
        "category",
        "nextBillingDate",
        "status",
        "notes",
        "paymentMethod"
      ],
      "properties": {
        "name": { "type": ["string", "null"] },
        "amount": { "type": ["number", "null"], "minimum": 0 },
        "currency": {
          "anyOf": [
            { "enum": ["USD", "EUR", "GBP", "INR", "CAD", "AUD"] },
            { "type": "null" }
          ]
        },
        "interval": {
          "anyOf": [
            { "enum": ["weekly", "monthly", "quarterly", "yearly"] },
            { "type": "null" }
          ]
        },
        "category": {
          "anyOf": [
            {
              "enum": [
                "entertainment",
                "software",
                "utilities",
                "health",
                "news",
                "shopping",
                "finance",
                "other"
              ]
            },
            { "type": "null" }
          ]
        },
        "nextBillingDate": { "type": ["string", "null"] },
        "status": {
          "anyOf": [
            { "enum": ["active", "paused", "cancelled"] },
            { "type": "null" }
          ]
        },
        "notes": { "type": ["string", "null"] },
        "paymentMethod": { "type": ["string", "null"] }
      }
    }
  }
}
