{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://synor.io/schemas/wallet.json",
  "title": "Synor Wallet SDK",
  "description": "Wallet management, key operations, and transaction signing",

  "$defs": {
    "WalletConfig": {
      "type": "object",
      "allOf": [{ "$ref": "common.json#/$defs/SynorConfig" }],
      "properties": {
        "network": {
          "type": "string",
          "enum": ["mainnet", "testnet"],
          "default": "mainnet"
        },
        "derivationPath": {
          "type": "string",
          "default": "m/44'/60'/0'/0"
        }
      }
    },

    "Wallet": {
      "type": "object",
      "properties": {
        "id": { "type": "string", "format": "uuid" },
        "address": { "$ref": "common.json#/$defs/Address" },
        "publicKey": { "$ref": "common.json#/$defs/PublicKey" },
        "createdAt": { "$ref": "common.json#/$defs/Timestamp" },
        "type": {
          "type": "string",
          "enum": ["standard", "multisig", "stealth", "hardware"]
        }
      },
      "required": ["id", "address", "publicKey", "type"]
    },

    "CreateWalletRequest": {
      "type": "object",
      "properties": {
        "passphrase": { "type": "string", "minLength": 8 },
        "type": {
          "type": "string",
          "enum": ["standard", "stealth"],
          "default": "standard"
        }
      }
    },

    "CreateWalletResponse": {
      "type": "object",
      "properties": {
        "wallet": { "$ref": "#/$defs/Wallet" },
        "mnemonic": {
          "type": "string",
          "description": "BIP39 mnemonic phrase (24 words)"
        }
      },
      "required": ["wallet", "mnemonic"]
    },

    "ImportWalletRequest": {
      "type": "object",
      "properties": {
        "mnemonic": { "type": "string" },
        "passphrase": { "type": "string" }
      },
      "required": ["mnemonic"]
    },

    "StealthAddress": {
      "type": "object",
      "properties": {
        "address": { "$ref": "common.json#/$defs/Address" },
        "viewKey": { "$ref": "common.json#/$defs/PublicKey" },
        "spendKey": { "$ref": "common.json#/$defs/PublicKey" },
        "ephemeralKey": { "$ref": "common.json#/$defs/PublicKey" }
      },
      "required": ["address", "viewKey", "spendKey"]
    },

    "TransactionInput": {
      "type": "object",
      "properties": {
        "txid": { "$ref": "common.json#/$defs/TxHash" },
        "vout": { "type": "integer", "minimum": 0 },
        "amount": { "$ref": "common.json#/$defs/Amount" }
      },
      "required": ["txid", "vout", "amount"]
    },

    "TransactionOutput": {
      "type": "object",
      "properties": {
        "address": { "$ref": "common.json#/$defs/Address" },
        "amount": { "$ref": "common.json#/$defs/Amount" }
      },
      "required": ["address", "amount"]
    },

    "Transaction": {
      "type": "object",
      "properties": {
        "version": { "type": "integer" },
        "inputs": {
          "type": "array",
          "items": { "$ref": "#/$defs/TransactionInput" }
        },
        "outputs": {
          "type": "array",
          "items": { "$ref": "#/$defs/TransactionOutput" }
        },
        "lockTime": { "type": "integer" },
        "fee": { "$ref": "common.json#/$defs/Amount" }
      },
      "required": ["version", "inputs", "outputs"]
    },

    "SignedTransaction": {
      "type": "object",
      "properties": {
        "raw": { "type": "string", "description": "Hex-encoded signed transaction" },
        "txid": { "$ref": "common.json#/$defs/TxHash" },
        "size": { "type": "integer" },
        "weight": { "type": "integer" }
      },
      "required": ["raw", "txid"]
    },

    "SignMessageRequest": {
      "type": "object",
      "properties": {
        "message": { "type": "string" },
        "format": {
          "type": "string",
          "enum": ["text", "hex", "base64"],
          "default": "text"
        }
      },
      "required": ["message"]
    },

    "SignMessageResponse": {
      "type": "object",
      "properties": {
        "signature": { "$ref": "common.json#/$defs/Signature" },
        "publicKey": { "$ref": "common.json#/$defs/PublicKey" },
        "address": { "$ref": "common.json#/$defs/Address" }
      },
      "required": ["signature", "publicKey", "address"]
    },

    "GetBalanceRequest": {
      "type": "object",
      "properties": {
        "address": { "$ref": "common.json#/$defs/Address" },
        "includeTokens": { "type": "boolean", "default": false }
      },
      "required": ["address"]
    },

    "TokenBalance": {
      "type": "object",
      "properties": {
        "token": { "$ref": "common.json#/$defs/Address" },
        "symbol": { "type": "string" },
        "decimals": { "type": "integer" },
        "balance": { "$ref": "common.json#/$defs/Amount" }
      },
      "required": ["token", "balance"]
    },

    "GetBalanceResponse": {
      "type": "object",
      "properties": {
        "native": { "$ref": "common.json#/$defs/Balance" },
        "tokens": {
          "type": "array",
          "items": { "$ref": "#/$defs/TokenBalance" }
        }
      },
      "required": ["native"]
    },

    "GetUtxosRequest": {
      "type": "object",
      "properties": {
        "address": { "$ref": "common.json#/$defs/Address" },
        "minConfirmations": { "type": "integer", "default": 1 },
        "minAmount": { "$ref": "common.json#/$defs/Amount" }
      },
      "required": ["address"]
    },

    "GetUtxosResponse": {
      "type": "object",
      "properties": {
        "utxos": {
          "type": "array",
          "items": { "$ref": "common.json#/$defs/UTXO" }
        },
        "total": { "$ref": "common.json#/$defs/Amount" }
      },
      "required": ["utxos", "total"]
    }
  }
}
