package com.gxwebsoft.shop.constants;

/**
 * 微信支付常量类
 * 管理微信支付相关的常量配置
 *
 * @author 科技小王子
 * @since 2025-01-26
 */
public class WxPayConstants {

    /**
     * 微信支付类型
     */
    public static class PayType {
        /** Native支付 */
        public static final String NATIVE = "NATIVE";
        /** JSAPI支付 */
        public static final String JSAPI = "JSAPI";
        /** H5支付 */
        public static final String MWEB = "MWEB";
        /** APP支付 */
        public static final String APP = "APP";
    }

    /**
     * 支付状态
     */
    public static class PayStatus {
        /** 支付成功 */
        public static final String SUCCESS = "SUCCESS";
        /** 转入退款 */
        public static final String REFUND = "REFUND";
        /** 未支付 */
        public static final String NOTPAY = "NOTPAY";
        /** 已关闭 */
        public static final String CLOSED = "CLOSED";
        /** 已撤销（付款码支付） */
        public static final String REVOKED = "REVOKED";
        /** 用户支付中（付款码支付） */
        public static final String USERPAYING = "USERPAYING";
        /** 支付失败（其他原因，如银行返回失败） */
        public static final String PAYERROR = "PAYERROR";
    }

    /**
     * 回调通知相关
     */
    public static class Notify {
        /** 成功响应 */
        public static final String SUCCESS_RESPONSE = "SUCCESS";
        /** 失败响应 */
        public static final String FAIL_RESPONSE = "FAIL";
        
        /** 通知类型 - 支付成功 */
        public static final String EVENT_TYPE_PAYMENT = "TRANSACTION.SUCCESS";
        /** 通知类型 - 退款成功 */
        public static final String EVENT_TYPE_REFUND = "REFUND.SUCCESS";
    }

    /**
     * 缓存键前缀
     */
    public static class CacheKey {
        /** 支付配置缓存键前缀 */
        public static final String PAYMENT_CONFIG_PREFIX = "Payment:wxPay:";
        /** 微信小程序配置缓存键 */
        public static final String MP_WEIXIN_CONFIG = "mp-weixin";
    }

    /**
     * 配置相关
     */
    public static class Config {
        /** 货币类型 - 人民币 */
        public static final String CURRENCY_CNY = "CNY";
        /** 金额转换倍数（元转分） */
        public static final int AMOUNT_MULTIPLIER = 100;
        
        /** 开发环境标识 */
        public static final String PROFILE_DEV = "dev";
        /** 生产环境标识 */
        public static final String PROFILE_PROD = "prod";
    }

    /**
     * 订单相关
     */
    public static class Order {
        /** 订单超时时间（分钟） */
        public static final int TIMEOUT_MINUTES = 30;
        /** 订单描述最大长度 */
        public static final int DESCRIPTION_MAX_LENGTH = 127;
    }

    /**
     * HTTP头部相关
     */
    public static class Header {
        /** 微信支付签名 */
        public static final String WECHATPAY_SIGNATURE = "Wechatpay-Signature";
        /** 微信支付时间戳 */
        public static final String WECHATPAY_TIMESTAMP = "Wechatpay-Timestamp";
        /** 微信支付随机数 */
        public static final String WECHATPAY_NONCE = "Wechatpay-Nonce";
        /** 微信支付序列号 */
        public static final String WECHATPAY_SERIAL = "Wechatpay-Serial";
        /** 请求ID */
        public static final String REQUEST_ID = "Request-ID";
    }

    /**
     * 错误信息
     */
    public static class ErrorMessage {
        /** 配置未找到 */
        public static final String CONFIG_NOT_FOUND = "微信支付配置未找到";
        /** 证书文件不存在 */
        public static final String CERTIFICATE_NOT_FOUND = "微信支付证书文件不存在";
        /** 参数验证失败 */
        public static final String PARAM_VALIDATION_FAILED = "参数验证失败";
        /** 签名验证失败 */
        public static final String SIGNATURE_VERIFICATION_FAILED = "签名验证失败";
        /** 订单不存在 */
        public static final String ORDER_NOT_FOUND = "订单不存在";
        /** 订单状态异常 */
        public static final String ORDER_STATUS_INVALID = "订单状态异常";
        /** 金额不匹配 */
        public static final String AMOUNT_MISMATCH = "订单金额不匹配";
        /** 网络请求失败 */
        public static final String NETWORK_REQUEST_FAILED = "网络请求失败";
        /** 系统内部错误 */
        public static final String SYSTEM_INTERNAL_ERROR = "系统内部错误";
    }

    /**
     * 日志相关
     */
    public static class LogMessage {
        /** 支付请求开始 */
        public static final String PAY_REQUEST_START = "开始处理微信支付请求";
        /** 支付请求成功 */
        public static final String PAY_REQUEST_SUCCESS = "微信支付请求处理成功";
        /** 支付请求失败 */
        public static final String PAY_REQUEST_FAILED = "微信支付请求处理失败";
        
        /** 回调处理开始 */
        public static final String CALLBACK_START = "开始处理微信支付回调";
        /** 回调处理成功 */
        public static final String CALLBACK_SUCCESS = "微信支付回调处理成功";
        /** 回调处理失败 */
        public static final String CALLBACK_FAILED = "微信支付回调处理失败";
        
        /** 配置加载成功 */
        public static final String CONFIG_LOADED = "微信支付配置加载成功";
        /** 配置加载失败 */
        public static final String CONFIG_LOAD_FAILED = "微信支付配置加载失败";
    }

    /**
     * 正则表达式
     */
    public static class Regex {
        /** 商户号格式 */
        public static final String MERCHANT_ID = "^\\d{10}$";
        /** 订单号格式 */
        public static final String ORDER_NO = "^[a-zA-Z0-9_-]{1,32}$";
        /** 金额格式（分） */
        public static final String AMOUNT = "^[1-9]\\d*$";
    }

    /**
     * 时间相关
     */
    public static class Time {
        /** 签名有效期（秒） */
        public static final long SIGNATURE_VALID_SECONDS = 300;
        /** 配置缓存有效期（秒） */
        public static final long CONFIG_CACHE_SECONDS = 3600;
    }

    /**
     * 文件相关
     */
    public static class File {
        /** 证书文件扩展名 */
        public static final String CERT_EXTENSION = ".pem";
        /** 私钥文件名 */
        public static final String PRIVATE_KEY_FILE = "apiclient_key.pem";
        /** 商户证书文件名 */
        public static final String MERCHANT_CERT_FILE = "apiclient_cert.pem";
        /** 平台证书文件名 */
        public static final String PLATFORM_CERT_FILE = "wechatpay_cert.pem";
    }

    // 私有构造函数，防止实例化
    private WxPayConstants() {
        throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
    }
}
