package shop.alien.entity.store.vo;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.List;

/**
 * 律师咨询订单视图对象（包含律师信息）
 *
 * @author system
 * @since 2025-01-XX
 */
@Data
@JsonInclude
@ApiModel(value = "LawyerConsultationOrderVO对象", description = "咨询订单视图对象（包含律师信息）")
public class LawyerConsultationOrderVO implements Serializable {

    @ApiModelProperty(value = "主键")
    private Integer id;

    @ApiModelProperty(value = "订单编号")
    private String orderNumber;

    @ApiModelProperty(value = "客户端用户ID")
    private Integer clientUserId;

    @ApiModelProperty(value = "律师用户ID")
    private Integer lawyerUserId;

    @ApiModelProperty(value = "法律问题场景ID")
    private String problemScenarioId;

    @ApiModelProperty(value = "问题描述")
    private String problemDescription;

    @ApiModelProperty(value = "订单金额,单位分")
    private Integer orderAmount;

    @ApiModelProperty(value = "咨询费用（本单收益）,单位分")
    private Integer consultationFee;

    @ApiModelProperty(value = "咨询开始时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date startTime;

    @ApiModelProperty(value = "咨询结束时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date endTime;

    @ApiModelProperty(value = "订单状态, 0:待支付,1.待接单 2:进行中, 3:已完成, 4:已取消，5.已退款")
    private Integer orderStatus;

    @ApiModelProperty(value = "支付状态, 0:未支付, 1:已支付")
    private Integer paymentStatus;

    @ApiModelProperty(value = "下单时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date orderTime;

    @ApiModelProperty(value = "支付时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date paymentTime;

    @ApiModelProperty(value = "订单有效期")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date validityPeriod;

    @ApiModelProperty(value = "用户评分, 1-5星")
    private Integer rating;

    @ApiModelProperty(value = "用户评价内容")
    private String comment;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createdTime;

    // ========== 律师信息 ==========

    @ApiModelProperty(value = "律师姓名")
    private String lawyerName;

    @ApiModelProperty(value = "律师手机号")
    private String lawyerPhone;

    @ApiModelProperty(value = "律师邮箱")
    private String lawyerEmail;

    @ApiModelProperty(value = "律师执业证号")
    private String lawyerCertificateNo;

    @ApiModelProperty(value = "所属律师事务所")
    private String lawFirm;

    @ApiModelProperty(value = "执业年限")
    private Integer practiceYears;

    @ApiModelProperty(value = "专业领域,多个用逗号分隔")
    private String specialtyFields;

    @ApiModelProperty(value = "资质认证状态, 0:未认证, 1:认证中, 2:已认证, 3:认证失败")
    private Integer certificationStatus;

    @ApiModelProperty(value = "服务评分, 0-5分")
    private Double serviceScore;

    @ApiModelProperty(value = "服务次数")
    private Integer serviceCount;

    @ApiModelProperty(value = "咨询收费标准(单位分/小时)")
    private Integer lawyerConsultationFee;

    @ApiModelProperty(value = "所属省份")
    private String province;

    @ApiModelProperty(value = "所属城市")
    private String city;

    @ApiModelProperty(value = "所属区县")
    private String district;

    @ApiModelProperty(value = "详细地址")
    private String address;

    @ApiModelProperty(value = "头像")
    private String headImg;

    @ApiModelProperty(value = "用户头像")
    private String userImage;

    @ApiModelProperty(value = "昵称")
    private String nickName;

    @ApiModelProperty(value = "个人简介(详细)")
    private String personalIntroduction;

    @ApiModelProperty(value = "法律场景列表")
    private List<String> lawyerLegalProblemScenarioList;

    @ApiModelProperty(value = "倒計時（秒），僅待支付訂單有效，30分鐘有效期")
    private Long countdownSeconds;

    @ApiModelProperty(value = "领域信息")
    private String expertiseAreaInfo;

    @ApiModelProperty(value = "客户端用户姓名")
    private String clientUserName;

    @ApiModelProperty(value = "客户端用户电话")
    private String clientUserPhone;

    @ApiModelProperty(value = "支付宝订单编号")
    @TableField("alipay_no")
    private String alipayNo;

    @ApiModelProperty(value = "支付宝订单字符串")
    @TableField("order_str")
    private String orderStr;

    @ApiModelProperty(value = "佣金比例")
    private String commissionRate;

    @ApiModelProperty(value = "佣金比例(前端使用)")
    private String commissionRateStr;

    @ApiModelProperty(value = "律师收益（订单金额-平台佣金）")
    private  Integer lawyerEarnings;

    @ApiModelProperty(value = "开始时间")
    private String startTimeNew;

    @ApiModelProperty(value = "结束时间")
    private String endTimeNew;

    @ApiModelProperty(value = "账号简介")
    private String accountBlurb;

    @ApiModelProperty(value = "律所名称")
    private String firmName;

    @ApiModelProperty(value = "律师接单时间")
    @TableField("accept_orders_time")
    private  Date acceptOrdersTime;

    @ApiModelProperty(value = "拒绝接单原因")
    @TableField("reason_order_refusal")
    private  String reasonOrderRefusal;

    @ApiModelProperty(value = "律师接单状态  0接单  1拒绝接单")
    @TableField("accept_orders_status")
    private  Integer acceptOrdersStatus;

    @ApiModelProperty(value = "申请退款原因")
    private  String applyRefundReason;

    @ApiModelProperty(value = "申请退款状态，0-未申请，1-已申请，2-律师已拒绝，3-律师已同意")
    @TableField("apply_refund_status")
    private  String applyRefundStatus;

    @ApiModelProperty(value = "是否被举报(1：被举报，2：未被举报)")
    private  String isViolation;

    @ApiModelProperty(value = "拒绝退款原因")
    private  String rejectRefundReason;

    @ApiModelProperty(value = "是否可申请退款(1-可申请，2-不可申请)")
    private  String isCanApplyRefund;

    @ApiModelProperty(value = "是否可申请举报(1-可举报，2-不可举报)")
    private  String isCanApplyViolation;

    @ApiModelProperty(value = "是否已经评价(1-已评价，2-未评价)")
    private  String isHasCommon;

    @ApiModelProperty(value = "用户申请退款时间")
    private  Date applyRefundTime;

    @ApiModelProperty(value = "申请退款处理时间")
    private  Date applyRefundProcessTime;

    @ApiModelProperty(value = "举报处理状态(0：待处理，1：已通过，2：已驳回)")
    private  String processingStatus;

    @ApiModelProperty(value = "举报处理时间")
    private  Date processingTime;

    @ApiModelProperty(value = "举报处理结果")
    private  String reportResult;

    @ApiModelProperty(value = "律师年限")
    private  Date practiceStartDate;

    @ApiModelProperty(value = "未读消息数量")
    private  Long unreadMessage;

    @ApiModelProperty(value = "律师接单状态")
    private int orderReceivingStatus;

    @ApiModelProperty(value = "申诉处理状态 0 审核中 1审核通过 2驳回")
    private String commentStatus;

    @ApiModelProperty(value = "评价状态 1：  没有评价，去评价 2：  有评价了，没有被举报或者举报驳回了，就是查看评价 3：  有评价了，被举报成功了，什么都不显示")
    private String commonStatus;

    @ApiModelProperty(value = "再次举报状态，0-不可以再次举报，1-可以再次举报")
    private  String repeatViolationStatus;

    @ApiModelProperty(value = "是否允许再次评论，true-允许，false-不允许（评论被举报且举报通过，评论已删除）")
    private Boolean canCommentAgain;

    /**
     * 获取执业年限（根据执业开始日期自动计算）
     * 返回当前时间减去执业开始时间的年数
     *
     * @return 执业年限（年）
     */
    public Integer getPracticeYears() {
        if (practiceStartDate == null) {
            return null;
        }
        try {
            // 将 Date 转换为 LocalDate
            LocalDate startDate = practiceStartDate.toInstant()
                    .atZone(ZoneId.systemDefault())
                    .toLocalDate();
            LocalDate currentDate = LocalDate.now();

            // 计算年数差
            long years = ChronoUnit.YEARS.between(startDate, currentDate);
            return (int) Math.max(0, years); // 确保不为负数
        } catch (Exception e) {
            return null;
        }
    }

    @ApiModelProperty(value = "支付方式 1支付宝 2微信")
    @TableField("pay_type")
    private  String payType;

    @ApiModelProperty(value = "分钟收费-钱数")
    private Integer chargeMinute;

    @ApiModelProperty(value = "分钟收费-分钟数")
    private Integer minuteNum;

    @ApiModelProperty(value = "次数收费-钱数")
    private Integer chargeTime;

    @ApiModelProperty(value = "次数收费-次数")
    private Integer timeNum;

    @ApiModelProperty(value = "订单金额字符串（拼接后的字段）")
    private String orderPriceStr;

}

