from enum import Enum, IntEnum
from .units import mm, inch

class Layer(IntEnum):
    F_Cu = 0
    B_Cu = 2
    In1_Cu = 4
    In2_Cu = 6
    In3_Cu = 8
    In4_Cu = 10
    In5_Cu = 12
    In6_Cu = 14
    In7_Cu = 16
    In8_Cu = 18
    In9_Cu = 20
    In10_Cu = 22
    In11_Cu = 24
    In12_Cu = 26
    In13_Cu = 28
    In14_Cu = 30
    In15_Cu = 32
    In16_Cu = 34
    In17_Cu = 36
    In18_Cu = 38
    In19_Cu = 40
    In20_Cu = 42
    In21_Cu = 44
    In22_Cu = 46
    In23_Cu = 48
    In24_Cu = 50
    In25_Cu = 52
    In26_Cu = 54
    In27_Cu = 56
    In28_Cu = 58
    In29_Cu = 60
    In30_Cu = 62

    B_Adhes = 11
    F_Adhes = 9
    B_Paste = 15
    F_Paste = 13
    B_SilkS = 7
    F_SilkS = 5
    B_Mask = 3
    F_Mask = 1

    Dwgs_User = 17
    Cmts_User = 19
    Eco1_User = 21
    Eco2_User = 23
    Edge_Cuts = 25
    Margin = 27

    B_CrtYd = 29
    F_CrtYd = 31
    B_Fab = 33
    F_Fab = 35

    User_1 = 39
    User_2 = 41
    User_3 = 43
    User_4 = 45
    User_5 = 47
    User_6 = 49
    User_7 = 51
    User_8 = 53
    User_9 = 55

    @staticmethod
    def allCu():
        return list(range(Layer.F_Cu, Layer.In30_Cu + 2, 2))

    @staticmethod
    def innerCu(layerCount):
        return list(range(Layer.In1_Cu, Layer.In1_Cu + (layerCount - 2) * 2, 2))

    @staticmethod
    def all():
        return (
            list(range(Layer.F_Cu, Layer.In30_Cu + 2, 2))
            + list(range(Layer.F_Mask, Layer.B_Paste + 2, 2))
            + list(range(Layer.Dwgs_User, Layer.Margin + 2, 2))
            + list(range(Layer.B_CrtYd, Layer.F_Fab + 2, 2))
            + list(range(Layer.User_1, Layer.User_9 + 2, 2))
        )

    @staticmethod
    def allTech():
        return [
            Layer.Dwgs_User,
            Layer.Cmts_User,
            Layer.Eco1_User,
            Layer.Eco2_User,
            Layer.Edge_Cuts,
            Layer.Margin,
            Layer.B_CrtYd,
            Layer.F_CrtYd,
            Layer.B_Fab,
            Layer.F_Fab
        ] + list(range(Layer.User_1, Layer.User_9 + 2, 2))

class STROKE_T(IntEnum):
    S_SEGMENT = 0
    S_RECT = 1
    S_ARC = 2
    S_CIRCLE = 3
    S_POLYGON = 4
    S_CURVE = 5

class EDA_TEXT_HJUSTIFY_T(IntEnum):
    GR_TEXT_HJUSTIFY_LEFT   = -1
    GR_TEXT_HJUSTIFY_CENTER = 0
    GR_TEXT_HJUSTIFY_RIGHT  = 1

class EDA_TEXT_VJUSTIFY_T(IntEnum):
    GR_TEXT_VJUSTIFY_TOP    = -1
    GR_TEXT_VJUSTIFY_CENTER = 0
    GR_TEXT_VJUSTIFY_BOTTOM = 1

class MODULE_ATTR_T(IntEnum):
    MOD_DEFAULT = 0,
    MOD_CMS     = 1
    MOD_VIRTUAL = 2

PAPER_SIZES = [f"A{size}" for size in range(6)] + ["A", "B", "C", "D", "E"] + \
              ["USLetter", "USLegal", "USLedger"]
PAPER_SIZES = PAPER_SIZES + [f"{paper}-portrait" for paper in PAPER_SIZES]

PAPER_DIMENSIONS = {
    "A5": (210 * mm, 148 * mm),
    "A4": (297 * mm, 210 * mm),
    "A3": (420 * mm, 297 * mm),
    "A2": (594 * mm, 420 * mm),
    "A1": (841 * mm, 594 * mm),
    "A0": (1198 * mm, 841 * mm),
    "A": (11 * inch, 8.5 * inch),
    "B": (17 * inch, 11 * inch),
    "C": (22 * inch, 17 * inch),
    "D": (34 * inch, 22 * inch),
    "E": (44 * inch, 34 * inch),
    "USLetter": (11 * inch, 8.5 * inch),
    "USLegal": (14 * inch, 8.5 * inch),
    "USLedger": (17 * inch, 11 * inch)
}
