package top.baogutang.admin.domain.res;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @description:
 * @author: nikooh
 * @date: 2024/08/22 : 10:06
 */
@Data
public class MarketCandlesRes implements Serializable {

    private static final long serialVersionUID = -3375737475097909682L;

    @JsonProperty("from")
    private String from;

    @JsonProperty("klines")
    private List<KLineData> kLineDataList;


    @Data
    public static class KLineData implements Serializable {

        private static final long serialVersionUID = 522558542163537197L;


        // 开盘价格
        @JsonProperty("开盘")
        private BigDecimal openPrice;

        // 最高价格
        @JsonProperty("最高")
        private BigDecimal highestPrice;

        // 最低价格
        @JsonProperty("最低")
        private BigDecimal lowestPrice;

        // 收盘价格
        @JsonProperty("收盘")
        private BigDecimal closePrice;

        // K线
        @JsonProperty("timestamp")
        private Long timestamp;

        @JsonProperty("时间")
        private String date;

        public static KLineData newInstance(String[] data, SimpleDateFormat dateFormat) {
            KLineData kLineData = new KLineData();
            kLineData.setOpenPrice(new BigDecimal(data[1]));
            kLineData.setHighestPrice(new BigDecimal(data[2]));
            kLineData.setLowestPrice(new BigDecimal(data[3]));
            kLineData.setClosePrice(new BigDecimal(data[4]));
            kLineData.setDate(dateFormat.format(new Date(Long.parseLong(data[0]))));
            return kLineData;
        }
    }
}
