{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://synor.io/schemas/governance.json",
  "title": "Synor Governance SDK",
  "description": "DAO, proposals, voting, and vesting management",

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

    "ProposalStatus": {
      "type": "string",
      "enum": ["draft", "pending", "active", "passed", "rejected", "executed", "cancelled", "expired"]
    },

    "ProposalType": {
      "type": "string",
      "enum": ["parameter_change", "treasury_spend", "contract_upgrade", "text", "emergency"]
    },

    "Proposal": {
      "type": "object",
      "properties": {
        "id": { "type": "string" },
        "title": { "type": "string" },
        "description": { "type": "string" },
        "type": { "$ref": "#/$defs/ProposalType" },
        "status": { "$ref": "#/$defs/ProposalStatus" },
        "proposer": { "$ref": "common.json#/$defs/Address" },
        "createdAt": { "$ref": "common.json#/$defs/Timestamp" },
        "votingStartsAt": { "$ref": "common.json#/$defs/Timestamp" },
        "votingEndsAt": { "$ref": "common.json#/$defs/Timestamp" },
        "executionDelay": { "$ref": "common.json#/$defs/Duration" },
        "quorum": { "$ref": "common.json#/$defs/Amount" },
        "currentQuorum": { "$ref": "common.json#/$defs/Amount" },
        "votesFor": { "$ref": "common.json#/$defs/Amount" },
        "votesAgainst": { "$ref": "common.json#/$defs/Amount" },
        "votesAbstain": { "$ref": "common.json#/$defs/Amount" },
        "actions": {
          "type": "array",
          "items": { "$ref": "#/$defs/ProposalAction" }
        }
      },
      "required": ["id", "title", "type", "status", "proposer"]
    },

    "ProposalAction": {
      "type": "object",
      "properties": {
        "target": { "$ref": "common.json#/$defs/Address" },
        "method": { "type": "string" },
        "args": { "type": "array" },
        "value": { "$ref": "common.json#/$defs/Amount" }
      },
      "required": ["target", "method"]
    },

    "ProposalDraft": {
      "type": "object",
      "properties": {
        "title": { "type": "string", "minLength": 10, "maxLength": 200 },
        "description": { "type": "string", "minLength": 50 },
        "type": { "$ref": "#/$defs/ProposalType" },
        "actions": {
          "type": "array",
          "items": { "$ref": "#/$defs/ProposalAction" }
        },
        "votingPeriod": { "$ref": "common.json#/$defs/Duration" }
      },
      "required": ["title", "description", "type"]
    },

    "ProposalFilter": {
      "type": "object",
      "properties": {
        "status": { "$ref": "#/$defs/ProposalStatus" },
        "type": { "$ref": "#/$defs/ProposalType" },
        "proposer": { "$ref": "common.json#/$defs/Address" }
      },
      "allOf": [{ "$ref": "common.json#/$defs/PaginationParams" }]
    },

    "VoteChoice": {
      "type": "string",
      "enum": ["for", "against", "abstain"]
    },

    "Vote": {
      "type": "object",
      "properties": {
        "proposalId": { "type": "string" },
        "choice": { "$ref": "#/$defs/VoteChoice" },
        "weight": { "$ref": "common.json#/$defs/Amount" },
        "reason": { "type": "string" }
      },
      "required": ["proposalId", "choice"]
    },

    "VoteReceipt": {
      "type": "object",
      "properties": {
        "txHash": { "$ref": "common.json#/$defs/TxHash" },
        "proposalId": { "type": "string" },
        "voter": { "$ref": "common.json#/$defs/Address" },
        "choice": { "$ref": "#/$defs/VoteChoice" },
        "weight": { "$ref": "common.json#/$defs/Amount" },
        "timestamp": { "$ref": "common.json#/$defs/Timestamp" }
      },
      "required": ["txHash", "proposalId", "voter", "choice", "weight"]
    },

    "DelegationReceipt": {
      "type": "object",
      "properties": {
        "txHash": { "$ref": "common.json#/$defs/TxHash" },
        "delegator": { "$ref": "common.json#/$defs/Address" },
        "delegatee": { "$ref": "common.json#/$defs/Address" },
        "amount": { "$ref": "common.json#/$defs/Amount" }
      },
      "required": ["txHash", "delegator", "delegatee", "amount"]
    },

    "VotingPower": {
      "type": "object",
      "properties": {
        "address": { "$ref": "common.json#/$defs/Address" },
        "ownPower": { "$ref": "common.json#/$defs/Amount" },
        "delegatedPower": { "$ref": "common.json#/$defs/Amount" },
        "totalPower": { "$ref": "common.json#/$defs/Amount" },
        "delegatedTo": { "$ref": "common.json#/$defs/Address" },
        "delegators": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "address": { "$ref": "common.json#/$defs/Address" },
              "amount": { "$ref": "common.json#/$defs/Amount" }
            }
          }
        }
      },
      "required": ["address", "totalPower"]
    },

    "DaoConfig": {
      "type": "object",
      "properties": {
        "name": { "type": "string" },
        "description": { "type": "string" },
        "token": { "$ref": "common.json#/$defs/Address" },
        "votingDelay": { "$ref": "common.json#/$defs/Duration" },
        "votingPeriod": { "$ref": "common.json#/$defs/Duration" },
        "proposalThreshold": { "$ref": "common.json#/$defs/Amount" },
        "quorumThreshold": { "$ref": "common.json#/$defs/Amount" }
      },
      "required": ["name", "token"]
    },

    "Dao": {
      "type": "object",
      "properties": {
        "id": { "type": "string" },
        "address": { "$ref": "common.json#/$defs/Address" },
        "name": { "type": "string" },
        "description": { "type": "string" },
        "token": { "$ref": "common.json#/$defs/Address" },
        "treasury": { "$ref": "common.json#/$defs/Address" },
        "proposalCount": { "type": "integer" },
        "memberCount": { "type": "integer" },
        "createdAt": { "$ref": "common.json#/$defs/Timestamp" }
      },
      "required": ["id", "address", "name", "token"]
    },

    "VestingSchedule": {
      "type": "object",
      "properties": {
        "beneficiary": { "$ref": "common.json#/$defs/Address" },
        "totalAmount": { "$ref": "common.json#/$defs/Amount" },
        "startTime": { "$ref": "common.json#/$defs/Timestamp" },
        "cliffDuration": { "$ref": "common.json#/$defs/Duration" },
        "vestingDuration": { "$ref": "common.json#/$defs/Duration" },
        "slicePeriod": { "$ref": "common.json#/$defs/Duration" },
        "revocable": { "type": "boolean" }
      },
      "required": ["beneficiary", "totalAmount", "startTime", "vestingDuration"]
    },

    "VestingContract": {
      "type": "object",
      "properties": {
        "id": { "type": "string" },
        "address": { "$ref": "common.json#/$defs/Address" },
        "schedule": { "$ref": "#/$defs/VestingSchedule" },
        "released": { "$ref": "common.json#/$defs/Amount" },
        "releasable": { "$ref": "common.json#/$defs/Amount" },
        "revoked": { "type": "boolean" }
      },
      "required": ["id", "address", "schedule", "released"]
    },

    "ClaimVestedRequest": {
      "type": "object",
      "properties": {
        "contractId": { "type": "string" }
      },
      "required": ["contractId"]
    }
  }
}
