package com.desfate.chart.ui.old.OTC.datas;

import java.util.ArrayList;
import java.util.Date;


public abstract class QuoteDayBase {

    private int exchangeCode;
    private String goodsCode;
    private String symbol;
    private Date openTime;
    private Date lastTime;
    private String price;
    private String bid;
    private String ask;
    private String opened;
    private String highest;
    private String lowest = "";
    private String preClose;
    private String preSettle; // 昨结算
    private String settle; // 结算价
    private int decimalPlace;
    private String upDownValue; // 涨跌额
    private String upDownRange; // 涨跌幅
    private String amplitude; // 振幅

    // 这个字段下发的时候，可能不存在 特殊字段

    protected String tradeType = "";

    //涨跌值，与昨结算、昨收比较
    private String strChange = "0";

    // 涨跌百分比，和昨收或昨结算比较
    private String strPctChange = "0";

    //涨跌值 ，与开盘时的价格比较
    private String strChangeSinceOpen;

    public String getStrChange() {
        return strChange;
    }

    public void setStrChange(String strChange) {
        this.strChange = strChange;
    }

    public String getStrPctChange() {
        return strPctChange;
    }

    public void setStrPctChange(String strPctChange) {
        this.strPctChange = strPctChange;
    }

    public String getStrChangeSinceOpen() {
        return strChangeSinceOpen;
    }

    public void setStrChangeSinceOpen(String strChangeSinceOpen) {
        this.strChangeSinceOpen = strChangeSinceOpen;
    }

    public String getTradeType() {
        return tradeType;
    }

    public void setTradeType(String tradeType) {
        this.tradeType = tradeType;
    }
    protected ArrayList<String> tradeTypes = new ArrayList<>();

    protected void init() {
        tradeTypes.clear();
        tradeTypes.add("P");
        tradeTypes.add("U");
        tradeTypes.add("D");
        tradeTypes.add("M");
        tradeTypes.add("X");
        tradeTypes.add("Y");
        tradeTypes.add("C");
    }

    /**
     * 是否可以用行情组新加累积分时和k
     * @return
     */
    public boolean canUseQuote() {
        return !tradeTypes.contains(tradeType);
    }

    /**
     * 顺序 买委托列队 accountname, accountId, orderId, qty,price
     */
    private String bidQueueInfo = "";
    /**
     * 顺序 卖委托列队 accountname, accountId, orderId, qty,price
     */
    private String askQueueInfo = "";


    public String getBidQueueInfo() {
        return bidQueueInfo;
    }

    public void setBidQueueInfo(String bidQueueInfo) {
        this.bidQueueInfo = bidQueueInfo;
    }

    public String getAskQueueInfo() {
        return askQueueInfo;
    }

    public void setAskQueueInfo(String askQueueInfo) {
        this.askQueueInfo = askQueueInfo;
    }


    public String getUpDownRange() {
        return upDownRange;
    }

    public String getAmplitude() {
        return amplitude;
    }

    public String getUpDownValue() {
        return upDownValue;
    }

    public void setAmplitude(String amplitude) {
        this.amplitude = amplitude;
    }

    public void setUpDownRange(String upDownRange) {
        this.upDownRange = upDownRange;
    }

    public void setUpDownValue(String upDownValue) {
        this.upDownValue = upDownValue;
    }

    public int getExchangeCode() {
        return exchangeCode;
    }

    public void setExchangeCode(int exchangeCode) {
        this.exchangeCode = exchangeCode;
    }

    public String getGoodsCode() {
        return goodsCode;
    }

    public void setGoodsCode(String goodsCode) {
        this.goodsCode = goodsCode;
    }

    public String getSymbol() {
        if (symbol == null || symbol.isEmpty()) {
            symbol = exchangeCode + goodsCode;
        }
        return symbol;
    }

    private void setSymbol(String symbol) {
        this.symbol = symbol;
    }

    public Date getLastTime() {
        return lastTime;
    }

    public void setLastTime(Date lastTime) {
        this.lastTime = lastTime;
    }

    public String getPrice() {
        if (price == null || "".equals(price) || "null".equals(price)) {
            return "0";
        }
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }

    public String getBid() {
        if (bid == null || bid.equals("") || bid.equals("null")) {
            bid = "0";
        }
        return bid;
    }

    public void setBid(String bid) {
        this.bid = bid;
    }

    public String getAsk() {
        if (ask == null || ask.equals("") || ask.equals("null")) {
            ask = "0";
        }
        return ask;
    }

    public void setAsk(String ask) {
        this.ask = ask;
    }

    public String getOpened() {
        if (!isEmpty(opened)) {
            opened = "0";
        }
        return opened;
    }

    public void setOpened(String opened) {
        this.opened = opened;
    }

    public String getHighest() {
        if (!isEmpty(highest)) {
            highest = "0";
        }
        return highest;
    }

    // 判断字符串是否为空 // FIXME: 2018/1/12 反人类啊。
    public static boolean isEmpty(String str) {
        return !(str == null || str.equals("") || str.equals("null"));// "" || null || "null" == false
    }

    public void setHighest(String highest) {
        this.highest = highest;
    }

    public String getLowest() {
        return lowest;
    }

    public void setLowest(String lowest) {
        this.lowest = lowest;
    }

    public int getDecimalPlace() {
        return decimalPlace;
    }

    public void setDecimalPlace(int decimalPlace) {
        this.decimalPlace = decimalPlace;
    }

    public void setPreClose(String param) {
        this.preClose = param;
    }

    /**
     * @return
     */
    public String getPreClose() {
        if (Double.parseDouble(getPreSettle()) != 0) {
            return getPreSettle();
        } else {
            if (preClose == null || preClose.equals("") || preClose.equals("null")) {
                preClose = "0";
            }
            if (Double.parseDouble(preClose) == 0) { // 如果做昨收价还是
                if (isEmpty(opened)) {
                    return opened;
                }
            }
        }
        return preClose;
    }

    /**
     * 取真正的昨收
     *
     * @return
     */
    public String getRealPreClose() {
        if (preClose == null || preClose.equals("") || preClose.equals("null")) {
            preClose = "0";
        }
        return preClose;
    }


    public void setPreSettle(String preSettle) {
        this.preSettle = preSettle;
    }

    public String getPreSettle() {
        if (preSettle == null || preSettle.equals("") || preSettle.equals("null")) {
            preSettle = "0";
        }
        return preSettle;
    }

    public void setSettle(String settle) {
        this.settle = settle;
    }

    public String getSettle() {
        if (settle == null || settle.equals("") || settle.equals("null")) {
            settle = "0";
        }
        return settle;
    }

    public abstract void inputQuote(QuoteTik quotes);

    public abstract void inputDayQuote(QuoteTik tik);

    // 和上一口价涨跌 上下箭头
    public abstract int getRaisedFlag();

    // 和昨收涨跌 买卖价变色
    public abstract int getUpDown();

    public Date getOpenTime() {
        return openTime;
    }

    public void setOpenTime(Date openTime) {
        this.openTime = openTime;
    }


    public void clearData() {
        exchangeCode = 0;
        goodsCode = "";
        symbol = "";
        Date openTime = null;
        Date lastTime = null;
        price = "";
        bid = "";
        ask = "";
        opened = "";
        highest = "";
        lowest = "";
        preClose = "";
        preSettle = ""; // 昨结算
        settle = ""; // 结算价
        decimalPlace = 0;
        upDownValue = ""; // 涨跌额
        upDownRange = ""; // 涨跌幅
        amplitude = ""; // 振幅
    }

}
