package com.yupi.project.model.vo;

import com.yupi.project.model.entity.ChargingSession;
import com.yupi.project.model.entity.User;
import com.yupi.project.model.enums.ChargingSessionStatusEnum;
import com.yupi.project.model.enums.PaymentStatusEnum;
import com.yupi.project.model.vo.UserVO;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 充电会话视图对象
 */
@Data
public class ChargingSessionVO implements Serializable {
    private static final long serialVersionUID = 1L;

    private Long id;
    private Long userId;
    private UserVO user; // 关联的用户信息 (脱敏后)
    private Long robotId;
    // private ChargingRobotVO robot; // 关联的机器人信息 (可选)
    private String robotUidSnapshot;
    private Long spotId;
    // private ParkingSpotVO spot; // 关联的车位信息 (可选)
    private String spotUidSnapshot;
    private String status;
    private String statusText; // 状态文本描述
    private Date requestTime;
    private Date robotAssignedTime;
    private Date robotArrivalTime;
    private Date chargeStartTime;
    private Date chargeEndTime;
    private Integer totalDurationSeconds;
    private BigDecimal energyConsumedKwh;
    private BigDecimal cost;
    private String paymentStatus;
    private String paymentStatusText; // 支付状态文本描述
    private String errorCode;
    private String errorMessage;
    private Long relatedRobotTaskId;
    private Date createTime;
    private Date updateTime;

    /**
     * 包装类转对象
     *
     * @param vo
     * @return
     */
    public static ChargingSession voToObj(ChargingSessionVO vo) {
        if (vo == null) {
            return null;
        }
        ChargingSession obj = new ChargingSession();
        BeanUtils.copyProperties(vo, obj);
        return obj;
    }

    /**
     * 对象转包装类
     *
     * @param obj
     * @return
     */
    public static ChargingSessionVO objToVo(ChargingSession obj) {
        if (obj == null) {
            return null;
        }
        ChargingSessionVO vo = new ChargingSessionVO();
        BeanUtils.copyProperties(obj, vo);
        // 根据枚举值设置 statusText 和 paymentStatusText
        if (obj.getStatus() != null) {
            ChargingSessionStatusEnum statusEnum = ChargingSessionStatusEnum.getEnumByValue(obj.getStatus());
            if (statusEnum != null) {
                vo.setStatusText(statusEnum.getDescription());
            }
        }
        if (obj.getPaymentStatus() != null) {
            PaymentStatusEnum paymentStatusEnum = PaymentStatusEnum.getEnumByValue(obj.getPaymentStatus());
            if (paymentStatusEnum != null) {
                vo.setPaymentStatusText(paymentStatusEnum.getDescription());
            }
        }
        return vo;
    }
    
    // 如果需要关联 UserVO 等，可以添加 set方法
    public void setUser(User user) {
        if (user != null) {
            this.user = UserVO.objToVo(user); // 假设 UserVO 也有类似的转换方法
        }
    }
} 