package com.ruoyi.blockchain.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

/**
 * 区块链配置类
 * 
 * @author ruoyi
 */
@Configuration
@ConfigurationProperties(prefix = "blockchain")
public class BlockchainConfig {
    
    /** 网络配置 */
    private Network network = new Network();
    
    /** 账户配置 */
    private Account account = new Account();
    
    /** 合约配置 */
    private Contract contract = new Contract();
    
    /** 隐私保护配置 */
    private Privacy privacy = new Privacy();
    
    public Network getNetwork() {
        return network;
    }
    
    public void setNetwork(Network network) {
        this.network = network;
    }
    
    public Account getAccount() {
        return account;
    }
    
    public void setAccount(Account account) {
        this.account = account;
    }
    
    public Contract getContract() {
        return contract;
    }
    
    public void setContract(Contract contract) {
        this.contract = contract;
    }
    
    public Privacy getPrivacy() {
        return privacy;
    }
    
    public void setPrivacy(Privacy privacy) {
        this.privacy = privacy;
    }
    
    /**
     * 网络配置
     */
    public static class Network {
        /** 网络URL */
        private String url = "http://localhost:8545";
        
        /** 链ID */
        private long chainId = 1337;
        
        /** 连接超时时间(毫秒) */
        private int connectionTimeout = 30000;
        
        /** 读取超时时间(毫秒) */
        private int readTimeout = 60000;
        
        /** 重试次数 */
        private int retryCount = 3;
        
        public String getUrl() {
            return url;
        }
        
        public void setUrl(String url) {
            this.url = url;
        }
        
        public long getChainId() {
            return chainId;
        }
        
        public void setChainId(long chainId) {
            this.chainId = chainId;
        }
        
        public int getConnectionTimeout() {
            return connectionTimeout;
        }
        
        public void setConnectionTimeout(int connectionTimeout) {
            this.connectionTimeout = connectionTimeout;
        }
        
        public int getReadTimeout() {
            return readTimeout;
        }
        
        public void setReadTimeout(int readTimeout) {
            this.readTimeout = readTimeout;
        }
        
        public int getRetryCount() {
            return retryCount;
        }
        
        public void setRetryCount(int retryCount) {
            this.retryCount = retryCount;
        }
    }
    
    /**
     * 账户配置
     */
    public static class Account {
        /** 私钥 */
        private String privateKey = "";
        
        /** 助记词 */
        private String mnemonic = "";
        
        /** 密码 */
        private String password = "";
        
        public String getPrivateKey() {
            return privateKey;
        }
        
        public void setPrivateKey(String privateKey) {
            this.privateKey = privateKey;
        }
        
        public String getMnemonic() {
            return mnemonic;
        }
        
        public void setMnemonic(String mnemonic) {
            this.mnemonic = mnemonic;
        }
        
        public String getPassword() {
            return password;
        }
        
        public void setPassword(String password) {
            this.password = password;
        }
    }
    
    /**
     * 合约配置
     */
    public static class Contract {
        /** 数据存储合约地址 */
        private String dataStorage = "";
        
        /** 资金分配合约地址 */
        private String fundDistribution = "";
        
        /** 债权管理合约地址 */
        private String creditManagement = "";
        
        /** Gas价格 */
        private long gasPrice = 20000000000L; // 20 Gwei
        
        /** Gas限制 */
        private long gasLimit = 6721975L;
        
        public String getDataStorage() {
            return dataStorage;
        }
        
        public void setDataStorage(String dataStorage) {
            this.dataStorage = dataStorage;
        }
        
        public String getFundDistribution() {
            return fundDistribution;
        }
        
        public void setFundDistribution(String fundDistribution) {
            this.fundDistribution = fundDistribution;
        }
        
        public String getCreditManagement() {
            return creditManagement;
        }
        
        public void setCreditManagement(String creditManagement) {
            this.creditManagement = creditManagement;
        }
        
        public long getGasPrice() {
            return gasPrice;
        }
        
        public void setGasPrice(long gasPrice) {
            this.gasPrice = gasPrice;
        }
        
        public long getGasLimit() {
            return gasLimit;
        }
        
        public void setGasLimit(long gasLimit) {
            this.gasLimit = gasLimit;
        }
    }
    
    /**
     * 隐私保护配置
     */
    public static class Privacy {
        /** 是否启用零知识证明 */
        private boolean enableZkProof = false;
        
        /** 是否启用同态加密 */
        private boolean enableHomomorphicEncryption = false;
        
        /** 数据最小化存储 */
        private boolean enableDataMinimization = true;
        
        /** 哈希算法 */
        private String hashAlgorithm = "SHA-256";
        
        public boolean isEnableZkProof() {
            return enableZkProof;
        }
        
        public void setEnableZkProof(boolean enableZkProof) {
            this.enableZkProof = enableZkProof;
        }
        
        public boolean isEnableHomomorphicEncryption() {
            return enableHomomorphicEncryption;
        }
        
        public void setEnableHomomorphicEncryption(boolean enableHomomorphicEncryption) {
            this.enableHomomorphicEncryption = enableHomomorphicEncryption;
        }
        
        public boolean isEnableDataMinimization() {
            return enableDataMinimization;
        }
        
        public void setEnableDataMinimization(boolean enableDataMinimization) {
            this.enableDataMinimization = enableDataMinimization;
        }
        
        public String getHashAlgorithm() {
            return hashAlgorithm;
        }
        
        public void setHashAlgorithm(String hashAlgorithm) {
            this.hashAlgorithm = hashAlgorithm;
        }
    }
}