package com.desfate.chart.data;

import android.os.Parcel;
import android.os.Parcelable;

import com.desfate.chart.entity.OHLCEntity;


public class ChartData extends OHLCEntity implements Parcelable {

    /**
     * 完美数据
     */
    public static final int Perfect = 0;

    /**
     * 自动画的
     */
    public static final int AutoDraw = 1;

    /**
     * 缺失补的
     */
    public static final int NoneDraw = 2;

    /**
     * 未设置
     */
    public static final int None = 3;

    private String mAmount = "";//!< @brief 成交金额
    private String mVolume = "";//!< @brief 总量

    private double mEMA12;//!< @brief EMA（12）
    private double mEMA26;//!< @brief EMA（26）
    private double mDIF;//!< @brief DIF
    private double mDEA;//!< @brief DEA
    private double mMACD;//!< @brief MACD

    /**
     * 数据类型
     * 0 正常数据，完美的数据
     * 1 随时间自动加进去的数据，这种数据是最垃圾的，每次生成新的都要尝试去修补以前的，
     * 而且不能计算入均价啥的里面
     * 2 由于漏了数据，然后填补空缺的数据，这种数据不能计算入均价里面，但是不需要再次请求，
     * 因为经过了服务端确认，没有数据
     */
    private int dataType = ChartData.None;
    // 是否是自己创建的数据, 如果在更新这种数据的时候，要重新更新开高低收
    private boolean isCreateBySelf = false;

    public ChartData() {
        super();
    }

    public ChartData(double open, double high, double low, double close, String time) {

        super(open, high, low, close, time);
    }

    protected ChartData(Parcel in) {
        mAmount = in.readString();
        mVolume = in.readString();
        mEMA12 = in.readDouble();
        mEMA26 = in.readDouble();
        mDIF = in.readDouble();
        mDEA = in.readDouble();
        mMACD = in.readDouble();
        dataType = in.readInt();
        isCreateBySelf = in.readByte() != 0;
    }

    public static final Creator<ChartData> CREATOR = new Creator<ChartData>() {
        @Override
        public ChartData createFromParcel(Parcel in) {
            return new ChartData(in);
        }

        @Override
        public ChartData[] newArray(int size) {
            return new ChartData[size];
        }
    };

    public void reset() {
        setOpen(0);
        setHigh(0);
        setLow(0);
        setClose(0);
        setTime("");
        mAmount = "";
        mVolume = "";
        mEMA12 = 0;
        mEMA26 = 0;
        mDIF = 0;
        mDEA = 0;
        mMACD = 0;
    }

    public String getAmount() {
        return mAmount;
    }

    public void setAmount(String value) {
        this.mAmount = value;
    }

    public String getVolume() {
        if ("".equals(mVolume)) {
            mVolume = "0";
        }
        return mVolume;
    }

    public void setVolume(String value) {
        this.mVolume = value;
    }

    public int getDataType() {
        return dataType;
    }

    public void setDataType(int dataType) {
        this.dataType = dataType;
    }

    public double getEMA12() {
        return mEMA12;
    }

    public void setEMA12(double value) {
        this.mEMA12 = value;
    }

    public double getEMA26() {
        return mEMA26;
    }

    public void setEMA26(double value) {
        this.mEMA26 = value;
    }

    public double getDIF() {
        return mDIF;
    }

    public void setDIF(double value) {
        this.mDIF = value;
    }

    public double getDEA() {
        return mDEA;
    }

    public void setDEA(double value) {
        this.mDEA = value;
    }

    public double getMACD() {
        return mMACD;
    }

    public void setMACD(double value) {
        this.mMACD = value;
    }

    @Override
    public int describeContents() {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        // TODO Auto-generated method stub

        dest.writeString(mAmount);
        dest.writeString(mVolume);
        dest.writeDouble(mEMA12);
        dest.writeDouble(mEMA26);
        dest.writeDouble(mDIF);
        dest.writeDouble(mDEA);
        dest.writeDouble(mMACD);
        dest.writeInt(dataType);
        dest.writeByte((byte) (isCreateBySelf ? 1 : 0));
    }

}
