{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://synor.io/schemas/hosting.json",
  "title": "Synor Hosting SDK",
  "description": "Domain management, DNS, deployments, and SSL certificates",

  "$defs": {
    "HostingConfig": {
      "type": "object",
      "allOf": [{ "$ref": "common.json#/$defs/SynorConfig" }]
    },

    "Domain": {
      "type": "object",
      "properties": {
        "name": { "type": "string" },
        "owner": { "$ref": "common.json#/$defs/Address" },
        "resolver": { "$ref": "common.json#/$defs/ContentId" },
        "registeredAt": { "$ref": "common.json#/$defs/Timestamp" },
        "expiresAt": { "$ref": "common.json#/$defs/Timestamp" },
        "verified": { "type": "boolean" }
      },
      "required": ["name", "owner"]
    },

    "DomainRecord": {
      "type": "object",
      "properties": {
        "domain": { "type": "string" },
        "cid": { "$ref": "common.json#/$defs/ContentId" },
        "dnslink": { "type": "string" },
        "ipv4": {
          "type": "array",
          "items": { "type": "string", "format": "ipv4" }
        },
        "ipv6": {
          "type": "array",
          "items": { "type": "string", "format": "ipv6" }
        },
        "updatedAt": { "$ref": "common.json#/$defs/Timestamp" }
      },
      "required": ["domain"]
    },

    "RegisterDomainRequest": {
      "type": "object",
      "properties": {
        "name": { "type": "string", "pattern": "^[a-z0-9-]+\\.synor$" },
        "duration": { "$ref": "common.json#/$defs/Duration" }
      },
      "required": ["name"]
    },

    "ResolveDomainRequest": {
      "type": "object",
      "properties": {
        "name": { "type": "string" }
      },
      "required": ["name"]
    },

    "UpdateDomainRequest": {
      "type": "object",
      "properties": {
        "name": { "type": "string" },
        "record": { "$ref": "#/$defs/DomainRecord" }
      },
      "required": ["name", "record"]
    },

    "DnsRecordType": {
      "type": "string",
      "enum": ["A", "AAAA", "CNAME", "TXT", "MX", "NS", "CAA", "DNSLINK"]
    },

    "DnsRecord": {
      "type": "object",
      "properties": {
        "type": { "$ref": "#/$defs/DnsRecordType" },
        "name": { "type": "string" },
        "value": { "type": "string" },
        "ttl": { "type": "integer", "minimum": 60, "default": 3600 },
        "priority": { "type": "integer", "minimum": 0 }
      },
      "required": ["type", "name", "value"]
    },

    "SetDnsRecordsRequest": {
      "type": "object",
      "properties": {
        "domain": { "type": "string" },
        "records": {
          "type": "array",
          "items": { "$ref": "#/$defs/DnsRecord" }
        }
      },
      "required": ["domain", "records"]
    },

    "GetDnsRecordsRequest": {
      "type": "object",
      "properties": {
        "domain": { "type": "string" },
        "type": { "$ref": "#/$defs/DnsRecordType" }
      },
      "required": ["domain"]
    },

    "DeploymentStatus": {
      "type": "string",
      "enum": ["queued", "building", "deploying", "ready", "failed", "cancelled"]
    },

    "Deployment": {
      "type": "object",
      "properties": {
        "id": { "type": "string" },
        "domain": { "type": "string" },
        "cid": { "$ref": "common.json#/$defs/ContentId" },
        "status": { "$ref": "#/$defs/DeploymentStatus" },
        "url": { "type": "string", "format": "uri" },
        "createdAt": { "$ref": "common.json#/$defs/Timestamp" },
        "readyAt": { "$ref": "common.json#/$defs/Timestamp" },
        "error": { "type": "string" }
      },
      "required": ["id", "domain", "cid", "status"]
    },

    "DeployRequest": {
      "type": "object",
      "properties": {
        "cid": { "$ref": "common.json#/$defs/ContentId" },
        "domain": { "type": "string" },
        "buildCommand": { "type": "string" },
        "outputDirectory": { "type": "string" },
        "environment": {
          "type": "object",
          "additionalProperties": { "type": "string" }
        }
      },
      "required": ["cid", "domain"]
    },

    "ListDeploymentsRequest": {
      "type": "object",
      "properties": {
        "domain": { "type": "string" },
        "status": { "$ref": "#/$defs/DeploymentStatus" }
      },
      "allOf": [{ "$ref": "common.json#/$defs/PaginationParams" }]
    },

    "Certificate": {
      "type": "object",
      "properties": {
        "domain": { "type": "string" },
        "issuer": { "type": "string" },
        "validFrom": { "$ref": "common.json#/$defs/Timestamp" },
        "validTo": { "$ref": "common.json#/$defs/Timestamp" },
        "fingerprint": { "type": "string" },
        "autoRenew": { "type": "boolean" }
      },
      "required": ["domain", "validFrom", "validTo"]
    },

    "ProvisionSslRequest": {
      "type": "object",
      "properties": {
        "domain": { "type": "string" },
        "wildcard": { "type": "boolean", "default": false }
      },
      "required": ["domain"]
    },

    "DomainVerification": {
      "type": "object",
      "properties": {
        "domain": { "type": "string" },
        "method": {
          "type": "string",
          "enum": ["dns", "http", "email"]
        },
        "token": { "type": "string" },
        "verified": { "type": "boolean" },
        "expiresAt": { "$ref": "common.json#/$defs/Timestamp" }
      },
      "required": ["domain", "method", "token"]
    }
  }
}
