{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://synor.io/schemas/common.json",
  "title": "Synor Common Types",
  "description": "Shared type definitions used across all Synor SDKs",

  "$defs": {
    "SynorConfig": {
      "type": "object",
      "description": "Base configuration for all Synor SDK clients",
      "properties": {
        "apiKey": {
          "type": "string",
          "description": "API key for authentication"
        },
        "endpoint": {
          "type": "string",
          "format": "uri",
          "description": "API endpoint URL"
        },
        "timeout": {
          "type": "integer",
          "minimum": 1000,
          "maximum": 300000,
          "default": 30000,
          "description": "Request timeout in milliseconds"
        },
        "retries": {
          "type": "integer",
          "minimum": 0,
          "maximum": 10,
          "default": 3,
          "description": "Number of retry attempts"
        },
        "debug": {
          "type": "boolean",
          "default": false,
          "description": "Enable debug logging"
        }
      },
      "required": ["apiKey"]
    },

    "Address": {
      "type": "string",
      "pattern": "^synor1[a-z0-9]{38}$",
      "description": "Synor blockchain address (bech32 encoded)"
    },

    "TxHash": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$",
      "description": "Transaction hash (32 bytes hex)"
    },

    "BlockHash": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$",
      "description": "Block hash (32 bytes hex)"
    },

    "ContentId": {
      "type": "string",
      "pattern": "^(Qm[1-9A-HJ-NP-Za-km-z]{44}|bafy[a-z0-9]{55})$",
      "description": "Content identifier (IPFS CID v0 or v1)"
    },

    "Amount": {
      "type": "string",
      "pattern": "^[0-9]+(\\.[0-9]+)?$",
      "description": "Decimal amount as string for precision"
    },

    "Timestamp": {
      "type": "integer",
      "minimum": 0,
      "description": "Unix timestamp in milliseconds"
    },

    "Duration": {
      "type": "integer",
      "minimum": 0,
      "description": "Duration in seconds"
    },

    "PublicKey": {
      "type": "string",
      "pattern": "^[a-f0-9]{66}$",
      "description": "Compressed public key (33 bytes hex)"
    },

    "Signature": {
      "type": "string",
      "pattern": "^[a-f0-9]{128,144}$",
      "description": "ECDSA or Schnorr signature"
    },

    "UTXO": {
      "type": "object",
      "properties": {
        "txid": { "$ref": "#/$defs/TxHash" },
        "vout": { "type": "integer", "minimum": 0 },
        "amount": { "$ref": "#/$defs/Amount" },
        "address": { "$ref": "#/$defs/Address" },
        "confirmations": { "type": "integer", "minimum": 0 },
        "scriptPubKey": { "type": "string" }
      },
      "required": ["txid", "vout", "amount", "address"]
    },

    "Balance": {
      "type": "object",
      "properties": {
        "confirmed": { "$ref": "#/$defs/Amount" },
        "unconfirmed": { "$ref": "#/$defs/Amount" },
        "total": { "$ref": "#/$defs/Amount" }
      },
      "required": ["confirmed", "unconfirmed", "total"]
    },

    "ChainId": {
      "type": "string",
      "enum": ["synor-mainnet", "synor-testnet", "ethereum", "bitcoin", "solana", "polygon", "arbitrum", "optimism"],
      "description": "Blockchain network identifier"
    },

    "Priority": {
      "type": "string",
      "enum": ["low", "medium", "high", "urgent"],
      "description": "Transaction priority level"
    },

    "Status": {
      "type": "string",
      "enum": ["pending", "processing", "completed", "failed", "cancelled"],
      "description": "Generic operation status"
    },

    "PaginationParams": {
      "type": "object",
      "properties": {
        "limit": { "type": "integer", "minimum": 1, "maximum": 100, "default": 20 },
        "offset": { "type": "integer", "minimum": 0, "default": 0 },
        "cursor": { "type": "string" }
      }
    },

    "PaginatedResponse": {
      "type": "object",
      "properties": {
        "items": { "type": "array" },
        "total": { "type": "integer" },
        "hasMore": { "type": "boolean" },
        "nextCursor": { "type": "string" }
      },
      "required": ["items", "hasMore"]
    },

    "ErrorCode": {
      "type": "string",
      "enum": [
        "INVALID_REQUEST",
        "AUTHENTICATION_FAILED",
        "AUTHORIZATION_DENIED",
        "RESOURCE_NOT_FOUND",
        "RATE_LIMITED",
        "INTERNAL_ERROR",
        "SERVICE_UNAVAILABLE",
        "TIMEOUT",
        "VALIDATION_ERROR",
        "INSUFFICIENT_FUNDS"
      ]
    },

    "ErrorResponse": {
      "type": "object",
      "properties": {
        "code": { "$ref": "#/$defs/ErrorCode" },
        "message": { "type": "string" },
        "details": { "type": "object" },
        "requestId": { "type": "string" }
      },
      "required": ["code", "message"]
    }
  }
}
