package com.haha.service.payment.payscore;

import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 支付分 - 回调解析结果
 */
@Data
public class PayScoreCallbackResult {
    
    /**
     * 是否成功解析
     */
    private boolean success;
    
    /**
     * 事件类型: PAYSCORE.USER_CONFIRMED / PAYSCORE.USER_PAID
     */
    private String eventType;
    
    /**
     * 商户服务订单号
     */
    private String outOrderNo;
    
    /**
     * 服务订单状态
     */
    private String state;
    
    /**
     * 总金额（元）
     */
    private BigDecimal totalAmount;
    
    /**
     * 用户OpenID
     */
    private String openId;
    
    /**
     * 支付完成时间
     */
    private LocalDateTime payTime;
    
    /**
     * 错误信息
     */
    private String errorMsg;

    /**
     * 取消原因（PAYSCORE.USER_CANCEL 回调时填充）
     */
    private String cancelReason;

    /**
     * 微信支付订单号（PAYSCORE.USER_PAID 回调时从 collection.details 提取，用于退款）
     */
    private String transactionId;
    
    public static PayScoreCallbackResult success(String eventType, String outOrderNo, String state) {
        PayScoreCallbackResult result = new PayScoreCallbackResult();
        result.setSuccess(true);
        result.setEventType(eventType);
        result.setOutOrderNo(outOrderNo);
        result.setState(state);
        return result;
    }
    
    public static PayScoreCallbackResult fail(String errorMsg) {
        PayScoreCallbackResult result = new PayScoreCallbackResult();
        result.setSuccess(false);
        result.setErrorMsg(errorMsg);
        return result;
    }
}
