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

import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonAnyGetter;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * StockValue 的扩展，增加换手率、流通股换手率、量比等数据
 * @author Barry
 *
 */
@Data
@EqualsAndHashCode(callSuper=false)
@NoArgsConstructor
@AllArgsConstructor
public class StockValueEx extends StockValue {

    private Double turnoverRate;
    private Double turnoverRateF;
    private Double volumeRatio;
    private Double pe;
    private Double peTtm;
    private Double pb;
    private Double ps;
    private Double psTtm;
    private Double dvRatio;
    private Double dvTtm;
    private Double totalShare;
    private Double floatShare;
    private Double freeShare;
    private Double totalMv;
    private Double circMv;
    
    /**
     * 获取换手率
     * @return
     */
    public Double getTurnoverRate() {
        if (turnoverRate == null) {
            if (totalShare == null || vol == null) return null;
            turnoverRate = vol * 100 / totalShare;
        }
        return turnoverRate;
    }
    
    /**
     * 获取换手率（流通盘）
     * @return
     */
    public Double getTurnoverRateF() {
        if (turnoverRateF == null) {
            if (floatShare == null || vol == null) return null;
            turnoverRateF = vol * 100 / floatShare;
        }
        return turnoverRateF;
    }
    
    @Setter(AccessLevel.NONE)
    @Getter(AccessLevel.NONE)
    @JsonAnyGetter
    private Map<String, Object> ext = new HashMap<>();
    
    public Object get(String key) {
        return ext.get(key);
    }
    
    public StockValueEx put(String key, Object object) {
        ext.put(key, object);
        return this;
    }
}
