package link.at17.mid.tushare.data.models;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import link.at17.mid.tushare.enums.StockSpan;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * 开/收/高/低/成交量/日期/股票间隔类型
 * @author Barry
 *
 */
@Data
@Accessors(chain=true)
@NoArgsConstructor
@AllArgsConstructor
public class StockValue {
    protected StockInfo stockInfo;
    protected Double open = 0d;
    protected Double close = 0d;
    protected Double high = 0d;
    protected Double low = 0d;
    protected Double vol = 0d;
    protected LocalDateTime date;
    protected StockSpan stockSpan = StockSpan.Daily;
    protected Double pctChg = null;
    protected Double pctChange = null;
    protected Double change = 0d;
    protected Double amount = 0d;
    
    public Double getPctChg() {
        if (pctChg == null && pctChange != null) {
            return pctChange;
        }
        return pctChg;
    }
    
    public Double getPctChange() {
        if (pctChange == null && pctChg != null) {
            return pctChg;
        }
        return pctChange;
    }
    
    public String getDateStr(String format) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
        return formatter.format(getDate());
    }
    
    public String getDateStr() {
        return getDateStr("yyyy-MM-dd");
    }
    
    protected void setFreq(int freq) {
        switch (freq) {
        case 1:
            stockSpan = StockSpan.Minute;
        case 5:
            stockSpan = StockSpan.Minute5;
            break;
        case 15:
            stockSpan = StockSpan.Minute15;
        case 30:
            stockSpan = StockSpan.Minute30;
        case 60:
            stockSpan = StockSpan.Minute60;
        }
    }
    
}
