{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://www.taylor-made-software.co.uk/srverless/schema/serverless-config.schema.json",
  "title": "Serverless Maven Plugin Configuration",
  "description": "Configuration file for the Serverless Maven Plugin",
  "type": "object",
  "required": ["name", "application", "provider", "regions"],
  "definitions": {
    "linkType": {
      "type": "string",
      "description": "Link type. Case-sensitive: must exactly match one of these values (the parser resolves it via LinkType.valueOf).",
      "enum": [
        "WEBSITE_TO_STORAGE", "WEBSITE_TO_API_GATEWAY",
        "API_GATEWAY_TO_FUNCTION", "API_GATEWAY_TO_AUTHENTICATION",
        "FUNCTION_TO_DATABASE", "FUNCTION_TO_STORAGE",
        "FUNCTION_TO_EMAIL", "FUNCTION_TO_SMS", "FUNCTION_TO_EVENT_BUS",
        "FUNCTION_TO_AUTHENTICATION", "FUNCTION_TO_DOMAIN", "FUNCTION_TO_FUNCTION",
        "FUNCTION_TO_API_GATEWAY",
        "EVENT_BUS_TO_FUNCTION", "AUTHENTICATION_TO_EMAIL", "AUTHENTICATION_TO_SMS",
        "WAF_TO_WEBSITE", "WAF_TO_API_GATEWAY"
      ]
    },
    "link": {
      "type": "object",
      "description": "A single link from this component to another component. Links are declared per-component inside the component's own 'links' array; there is no top-level links array.",
      "required": ["sourceComponent", "targetComponent", "linkType"],
      "properties": {
        "sourceComponent": {
          "type": "string",
          "description": "Source component name (usually this component)"
        },
        "targetComponent": {
          "type": "string",
          "description": "Target component name this link points to"
        },
        "linkType": { "$ref": "#/definitions/linkType" },
        "path": {
          "type": "string",
          "description": "URL path prefix for WEBSITE_TO_STORAGE links (must start with /). Routes requests matching this path to the target storage bucket via CloudFront.",
          "pattern": "^/"
        }
      }
    },
    "component": {
      "type": "object",
      "required": ["type", "name"],
      "properties": {
        "type": {
          "type": "string",
          "description": "Component type. Matched case-insensitively by the parser. 'function' and 'functions' are equivalent aliases for the serverless function group.",
          "enum": [
            "website", "storage", "api-gateway",
            "function", "functions",
            "database", "authentication", "email", "sms", "event-bus", "waf"
          ]
        },
        "name": {
          "type": "string",
          "description": "Unique component name within the configuration"
        },
        "providerSettings": {
          "type": "object",
          "description": "Component-specific settings. Shape varies by component type. See the component reference docs.",
          "additionalProperties": true
        },
        "links": {
          "type": "array",
          "description": "Links from this component to other components. Declared per-component (NOT at the root). Uses sourceComponent/targetComponent/linkType.",
          "items": { "$ref": "#/definitions/link" }
        }
      },
      "additionalProperties": true
    }
  },
  "properties": {
    "name": {
      "type": "string",
      "description": "Human-readable name for the application"
    },
    "description": {
      "type": "string",
      "description": "Optional description of the application"
    },
    "application": {
      "type": "string",
      "description": "Reverse-domain-notation application identifier (e.g. com.example.myapp)",
      "pattern": "^[a-z][a-z0-9]*(\\.[a-z][a-z0-9]*)+$"
    },
    "provider": {
      "type": "string",
      "description": "Target cloud provider",
      "enum": ["aws", "azure", "gcp"]
    },
    "variables": {
      "type": "object",
      "description": "Variable substitution map. Values are substituted for ${variableName} placeholders.",
      "additionalProperties": { "type": "string" }
    },
    "credentials": {
      "type": "object",
      "description": "Optional credentials configuration block. Shape is provider-specific.",
      "additionalProperties": true
    },
    "regions": {
      "type": "array",
      "description": "List of region configurations, each containing components to deploy",
      "items": {
        "type": "object",
        "required": ["region", "items"],
        "properties": {
          "region": {
            "type": "string",
            "description": "Cloud provider region identifier, or 'global' for global resources"
          },
          "items": {
            "type": "array",
            "description": "List of components to deploy in this region",
            "items": {
              "oneOf": [
                { "type": "string", "description": "Path to a component file" },
                { "$ref": "#/definitions/component" }
              ]
            }
          }
        }
      }
    }
  }
}
