package com.oo.eye.bean;

import android.content.Context;

import com.app.baselibrary.bean.BaseBean;
import com.app.baselibrary.commonUtil.DensityUtil;

/**
 * Created by henry  15/12/29.
 */
public class Eye extends BaseBean {
    public static final float percent = 2.1f;
    public static final float LEVEL_4_0 = Math.round(72.72f * percent);
    public static final float LEVEL_4_1 = Math.round(57.76f * percent);
    public static final float LEVEL_4_2 = Math.round(45.88f * percent);
    public static final float LEVEL_4_3 = Math.round(36.45f * percent);
    public static final float LEVEL_4_4 = Math.round(28.95f * percent);
    public static final float LEVEL_4_5 = Math.round(23.00f * percent);
    public static final float LEVEL_4_6 = Math.round(18.27f * percent);
    public static final float LEVEL_4_7 = Math.round(14.51f * percent);
    public static final float LEVEL_4_8 = Math.round(11.53f * percent);
    public static final float LEVEL_4_9 = Math.round(9.16f * percent);
    public static final float LEVEL_5_0 = Math.round(7.27f * percent);
    public static final float LEVEL_5_1 = Math.round(5.78f * percent);
    public static final float LEVEL_5_2 = Math.round(4.59f * percent);
    public static final float LEVEL_5_3 = Math.round(3.64f * percent);
//    public static final float LEVEL_5_3 = 5.0f;

    public static final float EYE_MARGIN = Math.round(24f * percent);
    public static final float EYE_BOARD_WIDTH = Math.round(217f * percent);
    public static final float EYE_BOARD_HEIGHT = 777f;
    public static final String UP = "上";
    public static final String BOTTOM = "下";
    public static final String RIGHT = "右";
    public static final String LEFT = "左";
    public static final String UNCLEAR = "看不清";

    public static final int DIRECT_UNCLEAR = -1;
    public static final int DIRECT_UP = 0;
    public static final int DIRECT_RIGHT = 1;
    public static final int DIRECT_BOTTOM = 2;
    public static final int DIRECT_LEFT = 3;


    /**
     * 每一行E标的大小
     * @param index
     * @return
     */
    public static float getLevelSizeByIndex(int index) {
        switch (index) {
            default:
            case 0:
                return LEVEL_4_0;
            case 1:
                return LEVEL_4_1;
            case 2:
                return LEVEL_4_2;
            case 3:
                return LEVEL_4_3;
            case 4:
                return LEVEL_4_4;
            case 5:
                return LEVEL_4_5;
            case 6:
                return LEVEL_4_6;
            case 7:
                return LEVEL_4_7;
            case 8:
                return LEVEL_4_8;
            case 9:
                return LEVEL_4_9;
            case 10:
                return LEVEL_5_0;
            case 11:
                return LEVEL_5_1;
            case 12:
                return LEVEL_5_2;
            case 13:
                return LEVEL_5_3;
        }

    }

    /**
     * 根据level获取对应的视力度数
     * @param index
     * @return
     */
    public static double getLevelByIndex(int index,boolean isFiveMeasure) {
        if(isFiveMeasure){
            //5米
            //(4.0 + (i * 0.1)) + "";
            switch (index) {
                default:
                case 0:
                    return 4.0;
                case 1:
                    return 4.1;
                case 2:
                    return 4.2;
                case 3:
                    return 4.3;
                case 4:
                    return 4.4;
                case 5:
                    return 4.5;
                case 6:
                    return 4.6;
                case 7:
                    return 4.7;
                case 8:
                    return 4.8;
                case 9:
                    return 4.9;
                case 10:
                    return 5.0;
                case 11:
                    return 5.1;
                case 12:
                    return 5.2;
                case 13:
                    return 5.3;
            }
        }else{
            switch (index) {
                default:
                case 0:
                    return 3.8;
                case 1:
                    return 3.9;
                case 2:
                    return 4.0;
                case 3:
                    return 4.1;
                case 4:
                    return 4.2;
                case 5:
                    return 4.3;
                case 6:
                    return 4.4;
                case 7:
                    return 4.5;
                case 8:
                    return 4.6;
                case 9:
                    return 4.7;
                case 10:
                    return 4.8;
                case 11:
                    return 4.9;
                case 12:
                    return 5.0;
                case 13:
                    return 5.1;
            }
        }

    }

    /**
     * 根据level获取对应的视力度数
     * @param index
     * @return
     */
    public static double get2LevelByIndex(int index,boolean isFiveMeasure) {
        if(isFiveMeasure){
            switch (index) {
                default:
                case 0:
                    return 0.1;
                case 1:
                    return 0.12;
                case 2:
                    return 0.15;
                case 3:
                    return 0.2;
                case 4:
                    return 0.25;
                case 5:
                    return 0.3;
                case 6:
                    return 0.4;
                case 7:
                    return 0.5;
                case 8:
                    return 0.6;
                case 9:
                    return 0.8;
                case 10:
                    return 1.0;
                case 11:
                    return 1.2;
                case 12:
                    return 1.5;
                case 13:
                    return 2.0;
            }
        }else{
            switch (index) {
                default:
                case 0:
                    return 0.06;
                case 1:
                    return 0.08;
                case 2:
                    return 0.1;
                case 3:
                    return 0.12;
                case 4:
                    return 0.15;
                case 5:
                    return 0.2;
                case 6:
                    return 0.25;
                case 7:
                    return 0.3;
                case 8:
                    return 0.4;
                case 9:
                    return 0.5;
                case 10:
                    return 0.6;
                case 11:
                    return 0.8;
                case 12:
                    return 1.0;
                case 13:
                    return 1.2;
            }
        }


    }

//    public static int getIndexByValue(String value) {
//        try {
//
//            double e = Double.valueOf(value);
//            return getIndexByValue(e);
//        } catch (Exception e) {
//            return 0;
//        }
//
//    }

    public static double transformSmall(double value){
        if (value <= 4.0) {
            return 0.1;
        } else if (value == 4.1) {
            return 0.12;
        } else if (value == 4.2) {
            return 0.15;
        } else if (value == 4.3) {
            return 0.2;
        } else if (value == 4.4) {
            return 0.25;
        } else if (value == 4.5) {
            return 0.3;
        } else if (value == 4.6) {
            return 0.4;
        } else if (value == 4.7) {
            return 0.5;
        } else if (value == 4.8) {
            return 0.6;
        } else if (value == 4.9) {
            return 0.8;
        } else if (value == 5.0) {
            return 1.0;
        } else if (value == 5.1) {
            return 1.2;
        } else if (value == 5.2) {
            return 1.5;
        } else if (value == 5.3) {
            return 2.5;
        }
        return 1.0;
    }

    /**
     * 测量的对照表
     * @param value
     * @return
     */
    public static int getIndexByValue(double value,boolean isFiveMeasure) {
        if(isFiveMeasure) {
            if (value == 0.06 || value == 3.8) {
                return 0;
            } else if (value == 0.08 || value == 3.9) {
                return 0;
            }else if (value == 0.1 || value == 4.0) {
                return 0;
            } else if (value == 0.12 || value == 4.1) {
                return 1;
            } else if (value == 0.15 || value == 4.2) {
                return 2;
            } else if (value == 0.2 || value == 4.3) {
                return 3;
            } else if (value == 0.25 || value == 4.4) {
                return 4;
            } else if (value == 0.3 || value == 4.5) {
                return 5;
            } else if (value == 0.4 || value == 4.6) {
                return 6;
            } else if (value == 0.5 || value == 4.7) {
                return 7;
            } else if (value == 0.6 || value == 4.8) {
                return 8;
            } else if (value == 0.8 || value == 4.9) {
                return 9;
            } else if (value == 1.0 || value == 5.0) {
                return 10;
            } else if (value == 1.2 || value == 5.1) {
                return 11;
            } else if (value == 1.5 || value == 5.2) {
                return 12;
            } else if (value == 2.5 || value == 5.3) {
                return 13;
            }
            return 10;
        }else{
            if (value == 0.06 || value == 3.8) {
                return 0;
            } else if (value == 0.08 || value == 3.9) {
                return 1;
            } else if (value == 0.1 || value == 4.0) {
                return 2;
            } else if (value == 0.12 || value == 4.1) {
                return 3;
            } else if (value == 0.15 || value == 4.2) {
                return 4;
            } else if (value == 0.2 || value == 4.3) {
                return 5;
            } else if (value == 0.25 || value == 4.4) {
                return 6;
            } else if (value == 0.3 || value == 4.5) {
                return 7;
            } else if (value == 0.4 || value == 4.6) {
                return 8;
            } else if (value == 0.5 || value == 4.7) {
                return 9;
            } else if (value == 0.6 || value == 4.8) {
                return 10;
            } else if (value == 0.8 || value == 4.9) {
                return 11;
            } else if (value == 1.0 || value == 5.0) {
                return 12;
            } else if (value == 1.2 || value == 5.1) {
                return 13;
            } else if (value == 1.5 || value == 5.2) {
                return 13;
            } else if (value == 2.5 || value == 5.3) {
                return 13;
            }
            return 10;
        }
    }

    /**
     * 根据等级  获取每行有多少个E
     * @param index  等级
     * @return
     */
    public static int getLineSumByIndex(int index) {
        switch (index) {
            default:
            case 0:
            case 1:
            case 2:
                return 2;
            case 3:
            case 4:
                return 3;
            case 5:
            case 6:
                return 4;
            case 7:
                return 5;
            case 8:
                return 6;
            case 9:
                return 7;
            case 10:
            case 11:
            case 12:
            case 13:
                return 8;
        }
    }
    //修改规则，

    /**
     * 1：受检者在距视力表5米处站立，用遮眼板将左眼轻轻遮上，先查右眼，后查左眼，均为裸眼视力
     * 2：可先从5.0一行视标认起。如果看不清再逐行上查，如辨认无误则逐行下查。要求对每个视标的识别时间不超过所设置的时间
     * 3：规定4.0～4.7各行视标不能认错，错了就向上一行，4.8～5.0各行视标中每行不能认错2个，错了就上一行，5.1～5.3各行视标中每行不能认错3个
     * 4：超过这一规定就不再往下检查，而以本行的上一行记为该受检者的视力值
     *
     * @param index
     * @return
     */
    public static int getLeastAnswerCount(int index) {
        int sum = getLineSumByIndex(index);
        switch (index) {
            default:
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
                return sum;
            case 8:
            case 9:
            case 10:
                return sum - 2;
            case 11:
            case 12:
            case 13:
                return sum - 3;
        }
//        if (sum % 2 == 0) {
//            return sum / 2;
//        } else {
//            return sum / 2 + 1;
//        }
    }

    public static float getDp(float level) {
        return level * 2;
    }

    public static int calcMargin(Context context, int count, float level) {

        float space = EYE_BOARD_WIDTH - (level * count);

        if (count == 1) {
            return 0;
        }

        float mm = space / ((count - 1) * 2);

        return getPx(context, mm);

    }

    public static int getPx(Context context, float level) {
        //return DimUtil.dip2px(context, getDp(level));
        return getDip(context, level);
    }

    public static int getDip(Context context, float level) {
        return DensityUtil.px2dip(level);
    }


    public static String getDirectStr(int direct) {
        switch (direct) {
            default:
            case DIRECT_UNCLEAR:
                return UNCLEAR;
            case DIRECT_UP:
                return UP;
            case DIRECT_RIGHT:
                return RIGHT;
            case DIRECT_BOTTOM:
                return BOTTOM;
            case DIRECT_LEFT:
                return LEFT;
        }
    }

    public static class E {
        private int index;
        private int direct;
        private float level;
        private int userChoose;
        private int x;
        private int y;
        private int width;

        public E(int index, int direct, float level) {
            this.index = index;
            this.direct = direct;
            this.level = level;
        }

        public boolean isCorrect() {
            return direct == userChoose;
        }

        public void setUserChoose(int userChoose) {
            this.userChoose = userChoose;
        }

        public int getUserChoose() {
            return userChoose;
        }

        public int getDirect() {
            return direct;
        }

        public int getIndex() {
            return index;
        }

        public float getLevel() {
            return level;
        }

        public int getX() {
            return x;
        }

        public void setX(int x) {
            this.x = x;
        }

        public int getY() {
            return y;
        }

        public void setY(int y) {
            this.y = y;
        }

        public int getWidth() {
            return width;
        }

        public void setWidth(int width) {
            this.width = width;
        }
    }
}
