package com.qmth.teachcloud.common.enums;

import com.qmth.teachcloud.common.contant.SystemConstant;

/**
 * @Description: pdf格式 enum
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2021/4/7
 */
public enum PageSizeEnum {
    A0(2384.0F, 3370.0F),
    A1(1684.0F, 2384.0F),
    A2(1191.0F, 1684.0F),
    A3(842.0F, 1191.0F),
    A4(595.0F, 842.0F),
    A5(420.0F, 595.0F),
    A6(297.0F, 420.0F),
    A7(210.0F, 297.0F),
    A8(148.0F, 210.0F),
    A9(105.0F, 148.0F),
    A10(73.0F, 105.0F),
    B0(2834.0F, 4008.0F),
    B1(2004.0F, 2834.0F),
    B2(1417.0F, 2004.0F),
    B3(1000.0F, 1417.0F),
    B4(708.0F, 1000.0F),
    B5(498.0F, 708.0F),
    B6(354.0F, 498.0F),
    B7(249.0F, 354.0F),
    B8(175.0F, 249.0F),
    B9(124.0F, 175.0F),
    B10(87.0F, 124.0F),
    ARCH_E(2592.0F, 3456.0F),
    ARCH_D(1728.0F, 2592.0F),
    ARCH_C(1296.0F, 1728.0F),
    ARCH_B(864.0F, 1296.0F),
    ARCH_A(648.0F, 864.0F),
    FLSA(612.0F, 936.0F),
    FLSE(648.0F, 936.0F),
    HALFLETTER(396.0F, 612.0F),
    _11X17(792.0F, 1224.0F),
    ID_1(242.65F, 153.0F),
    ID_2(297.0F, 210.0F),
    ID_3(354.0F, 249.0F),
    LEDGER(1224.0F, 792.0F),
    CROWN_QUARTO(535.0F, 697.0F),
    LARGE_CROWN_QUARTO(569.0F, 731.0F),
    DEMY_QUARTO(620.0F, 782.0F),
    ROYAL_QUARTO(671.0F, 884.0F),
    CROWN_OCTAVO(348.0F, 527.0F),
    LARGE_CROWN_OCTAVO(365.0F, 561.0F),
    DEMY_OCTAVO(391.0F, 612.0F),
    ROYAL_OCTAVO(442.0F, 663.0F),
    SMALL_PAPERBACK(314.0F, 504.0F),
    PENGUIN_SMALL_PAPERBACK(314.0F, 513.0F),
    PENGUIN_LARGE_PAPERBACK(365.0F, 561.0F);

    private float width;

    private float height;

    private PageSizeEnum(float width, float height) {
        this.width = width;
        this.height = height;
    }

    public float getWidth() {
        return width;
    }

    public float getHeight() {
        return height;
    }

    /**
     * 状态转换 toName
     *
     * @param width
     * @param height
     * @return
     */
    public static String convertToName(float width, float height) {
        float deviation = SystemConstant.PAPER_DEVIATION;
        for (PageSizeEnum e : PageSizeEnum.values()) {
            float standardWidth = e.getWidth();
            float standardHeight = e.getHeight();
            if (standardWidth - deviation <= width && width <= standardWidth + deviation && standardHeight - deviation <= height && height <= standardHeight + deviation){
                return e.name();
            }
        }
        return null;
    }

    /**
     * 状态转换 toEnum
     *
     * @param width
     * @param height
     * @return
     */
    public static PageSizeEnum convertToEnum(float width, float height) {
        float deviation = SystemConstant.PAPER_DEVIATION;
        for (PageSizeEnum e : PageSizeEnum.values()) {
            float standardWidth = e.getWidth();
            float standardHeight = e.getHeight();
            if (standardWidth - deviation <= width && width <= standardWidth + deviation && standardHeight - deviation <= height && height <= standardHeight + deviation){
                return e;
            }
        }
        throw ExceptionResultEnum.ERROR.exception("pdf格式不符合标准规范，请提供标准的pdf（可使用wps、office的word转换）");
    }
}
