{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://synor.io/schemas/bridge.json",
  "title": "Synor Bridge SDK",
  "description": "Cross-chain asset transfers and bridging operations",

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

    "Asset": {
      "type": "object",
      "properties": {
        "chain": { "$ref": "common.json#/$defs/ChainId" },
        "address": { "type": "string" },
        "symbol": { "type": "string" },
        "decimals": { "type": "integer" },
        "isNative": { "type": "boolean" },
        "isWrapped": { "type": "boolean" }
      },
      "required": ["chain", "symbol", "decimals"]
    },

    "Chain": {
      "type": "object",
      "properties": {
        "id": { "$ref": "common.json#/$defs/ChainId" },
        "name": { "type": "string" },
        "rpcUrl": { "type": "string", "format": "uri" },
        "explorerUrl": { "type": "string", "format": "uri" },
        "nativeCurrency": { "$ref": "#/$defs/Asset" },
        "confirmationsRequired": { "type": "integer" }
      },
      "required": ["id", "name"]
    },

    "TransferStatus": {
      "type": "string",
      "enum": ["pending", "locked", "minting", "minted", "burning", "unlocking", "completed", "failed", "refunded"]
    },

    "Transfer": {
      "type": "object",
      "properties": {
        "id": { "type": "string" },
        "status": { "$ref": "#/$defs/TransferStatus" },
        "sourceChain": { "$ref": "common.json#/$defs/ChainId" },
        "targetChain": { "$ref": "common.json#/$defs/ChainId" },
        "sourceAddress": { "type": "string" },
        "targetAddress": { "type": "string" },
        "asset": { "$ref": "#/$defs/Asset" },
        "amount": { "$ref": "common.json#/$defs/Amount" },
        "fee": { "$ref": "common.json#/$defs/Amount" },
        "sourceTxHash": { "type": "string" },
        "targetTxHash": { "type": "string" },
        "createdAt": { "$ref": "common.json#/$defs/Timestamp" },
        "completedAt": { "$ref": "common.json#/$defs/Timestamp" }
      },
      "required": ["id", "status", "sourceChain", "targetChain", "asset", "amount"]
    },

    "LockRequest": {
      "type": "object",
      "properties": {
        "asset": { "$ref": "#/$defs/Asset" },
        "amount": { "$ref": "common.json#/$defs/Amount" },
        "targetChain": { "$ref": "common.json#/$defs/ChainId" },
        "targetAddress": { "type": "string" }
      },
      "required": ["asset", "amount", "targetChain", "targetAddress"]
    },

    "LockReceipt": {
      "type": "object",
      "properties": {
        "transferId": { "type": "string" },
        "txHash": { "type": "string" },
        "lockProof": { "$ref": "#/$defs/LockProof" },
        "estimatedCompletion": { "$ref": "common.json#/$defs/Timestamp" }
      },
      "required": ["transferId", "txHash"]
    },

    "LockProof": {
      "type": "object",
      "properties": {
        "blockHash": { "type": "string" },
        "blockNumber": { "type": "integer" },
        "txHash": { "type": "string" },
        "logIndex": { "type": "integer" },
        "proof": {
          "type": "array",
          "items": { "type": "string" }
        },
        "signatures": {
          "type": "array",
          "items": { "$ref": "common.json#/$defs/Signature" }
        }
      },
      "required": ["blockHash", "blockNumber", "txHash", "proof"]
    },

    "MintRequest": {
      "type": "object",
      "properties": {
        "proof": { "$ref": "#/$defs/LockProof" },
        "targetAddress": { "type": "string" }
      },
      "required": ["proof", "targetAddress"]
    },

    "BurnRequest": {
      "type": "object",
      "properties": {
        "wrappedAsset": { "$ref": "#/$defs/Asset" },
        "amount": { "$ref": "common.json#/$defs/Amount" }
      },
      "required": ["wrappedAsset", "amount"]
    },

    "BurnReceipt": {
      "type": "object",
      "properties": {
        "transferId": { "type": "string" },
        "txHash": { "type": "string" },
        "burnProof": { "$ref": "#/$defs/BurnProof" }
      },
      "required": ["transferId", "txHash"]
    },

    "BurnProof": {
      "type": "object",
      "properties": {
        "blockHash": { "type": "string" },
        "blockNumber": { "type": "integer" },
        "txHash": { "type": "string" },
        "proof": {
          "type": "array",
          "items": { "type": "string" }
        }
      },
      "required": ["blockHash", "txHash", "proof"]
    },

    "UnlockRequest": {
      "type": "object",
      "properties": {
        "proof": { "$ref": "#/$defs/BurnProof" }
      },
      "required": ["proof"]
    },

    "TransferFilter": {
      "type": "object",
      "properties": {
        "status": { "$ref": "#/$defs/TransferStatus" },
        "sourceChain": { "$ref": "common.json#/$defs/ChainId" },
        "targetChain": { "$ref": "common.json#/$defs/ChainId" },
        "address": { "type": "string" }
      },
      "allOf": [{ "$ref": "common.json#/$defs/PaginationParams" }]
    },

    "ExchangeRate": {
      "type": "object",
      "properties": {
        "from": { "$ref": "#/$defs/Asset" },
        "to": { "$ref": "#/$defs/Asset" },
        "rate": { "$ref": "common.json#/$defs/Amount" },
        "fee": { "$ref": "common.json#/$defs/Amount" },
        "minAmount": { "$ref": "common.json#/$defs/Amount" },
        "maxAmount": { "$ref": "common.json#/$defs/Amount" },
        "estimatedTime": { "$ref": "common.json#/$defs/Duration" }
      },
      "required": ["from", "to", "rate", "fee"]
    },

    "GetSupportedChainsResponse": {
      "type": "object",
      "properties": {
        "chains": {
          "type": "array",
          "items": { "$ref": "#/$defs/Chain" }
        }
      },
      "required": ["chains"]
    },

    "GetSupportedAssetsRequest": {
      "type": "object",
      "properties": {
        "chain": { "$ref": "common.json#/$defs/ChainId" }
      },
      "required": ["chain"]
    },

    "GetExchangeRateRequest": {
      "type": "object",
      "properties": {
        "from": { "$ref": "#/$defs/Asset" },
        "to": { "$ref": "#/$defs/Asset" },
        "amount": { "$ref": "common.json#/$defs/Amount" }
      },
      "required": ["from", "to"]
    }
  }
}
