package com.kym.entity.platform;

import com.alibaba.fastjson2.annotation.JSONCreator;
import com.alibaba.fastjson2.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.kym.entity.miniapp.vo.PlatformPolicyInfoVo;
import lombok.Data;

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
 * @author skyline
 * @description 分时费率
 * @date 2023-08-15 16:11
 */
@Data
public class PlatformPolicyInfo {
    public final static String[] PRICE_PERIOD = {"谷", "平", "峰", "尖"};
    /**
     * 价格时段（尖峰平谷）
     */
    public String pricePeriod;
    /**
     * 时段开始时间点
     */
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm:ss", timezone = "GMT+8")
    private LocalTime startTime;
    /**
     * 时段电费 小数点后4位
     */
    @JSONField(name = "ElecPrice")
    private Double elecPrice;
    /**
     * 时段服务费 小数点后4位
     */
    @JSONField(name = "SevicePrice")
    private Double servicePrice;

    @JSONCreator
    PlatformPolicyInfo(@JSONField(name = "StartTime", serialize = false) String startTime) {
        this.startTime = LocalTime.parse(startTime, DateTimeFormatter.ofPattern("HHmmss"));
    }

    public static PlatformPolicyInfoVo toVo(PlatformPolicyInfo info) {
        PlatformPolicyInfoVo vo = new PlatformPolicyInfoVo();
        vo.setPricePeriod(info.pricePeriod);
        vo.setStartTime(info.startTime);
        vo.setElecPrice(info.elecPrice);
        vo.setServicePrice(info.servicePrice);
        return vo;
    }
}
