# Generated by Django 3.1.4 on 2020-12-15 17:40

from django.db import migrations
from django.core.files.images import ImageFile


def default_data(apps, schema_editor):
    Workshop = apps.get_model('inventory', 'Workshop')
    Area = apps.get_model('inventory', 'Area')
    Layout = apps.get_model('inventory', 'Layout')
    FormFactor = apps.get_model('inventory', 'FormFactor')
    Distributor = apps.get_model('inventory', 'Distributor')
    Settings = apps.get_model('inventory', 'Settings')
    Tag = apps.get_model('inventory', 'Tag')

    Settings.objects.create(default_container=None)

    tag_smd = Tag.objects.create(name='SMD', description='SMD')
    tag_tht = Tag.objects.create(name='THT', description='Through hole')
    tag_imperial = Tag.objects.create(name='Imperial', description='Imperial measurements')
    tag_metric = Tag.objects.create(name='Metric', description='Metric measurements')
    tag_passive = Tag.objects.create(name='Passive', description='Passive part')
    tag_capacitor = Tag.objects.create(name='Capacitor', description='Capacitor')
    tag_electrolytic = Tag.objects.create(name='Electrolytic', description='Electrolytic capacitor')
    tag_tantalum = Tag.objects.create(name='Tantalum', description='Tantalum capacitor')
    tag_diode = Tag.objects.create(name='Diode', description='Diode')
    tag_resistor = Tag.objects.create(name='Resistor', description='Resistor')  # noqa: F841
    tag_chip = Tag.objects.create(name='Chip', description='Chip')
    tag_polarized = Tag.objects.create(name='Polarized', description='Polarized part')
    tag_terminals = {}
    for i in range(2, 65):
        if i > 10 and i % 2 != 0:
            continue
        tag_terminals[i] = Tag.objects.create(
            name="Terminals:{}".format(i),
            description='{} terminals'.format(i)
        )
    tag_terminals[128] = Tag.objects.create(name='Terminals:128', description='128 terminals')

    pin_spacing = [
        '0.4', '0.5', '0.635', '0.65', '0.8', '1.27', '1.0',
        '1.78', '2.0',
        '2.5', '2.29', '2.54', '3.5',
        '5.0', '5.08', '7.5'
    ]
    tag_pin_spacing = {}
    for i in pin_spacing:
        tag_pin_spacing[i] = Tag.objects.create(
            name='PinSpacing:{}'.format(i),
            description='Pin spacing {}mm'.format(i)
        )

    tag_row_spacing_7_62 = Tag.objects.create(name='RowSpacing:7.62', description='Row spacing 7.62mm')
    tag_row_spacing_15_24 = Tag.objects.create(name='RowSpacing:15.24', description='Row spacing 15.24mm')

    tag_metal_can = Tag.objects.create(name='MetalCan', description='Metal can')
    tag_plastic_package = Tag.objects.create(name='PlasticPackage', description='Plastic package')
    tag_panel_mount = Tag.objects.create(name='PanelMount', description='Panel mount')
    tag_power_package = Tag.objects.create(name='PowerPackage', description='Power package')

    tag_germany = Tag.objects.create(name='Germany', description='Germany specific')
    tag_uk = Tag.objects.create(name='UK', description='United Kingdom specific')
    tag_usa = Tag.objects.create(name='US', description='United States of America specific')

    single_item_layout = Layout.objects.create(
        name='Single item',
        description='Default layout for a single item',
        data=[1000]
    )

    workshop = Workshop.objects.create(
        name="Default Workshop",
        description="Default Workshop",
        layout=single_item_layout
    )

    Area.objects.create(
        name="Main Area",
        description="Main Area in default workshop",
        layout=single_item_layout,
        container=workshop,
        index=0
    )

    tags_passive = [tag_smd, tag_passive, tag_imperial, tag_terminals[2]]
    tags_tantalum = [tag_smd, tag_capacitor, tag_tantalum, tag_metric, tag_terminals[2]]
    tags_electrolytic = [tag_smd, tag_capacitor, tag_electrolytic, tag_polarized, tag_metric, tag_terminals[2]]
    tags_diode = [tag_smd, tag_polarized, tag_terminals[2]]
    smd_2_terminal = [tag_smd, tag_terminals[2]]

    def create_ff(name, description, tags):
        ff = FormFactor.objects.create(
            name=name,
            description=description
        )
        ff.tags.set(tags)

    def create_chip(name, min_pin, max_pin, sides=2, tags=None, aka=None):
        FormFactor = apps.get_model('inventory', 'FormFactor')
        if tags is None:
            tags = [tag_chip]
        else:
            tags.append(tag_chip)

        for pins in range(min_pin, max_pin + 1, sides):
            if pins > 20 and pins % 4 != 0:
                continue
            ff = FormFactor.objects.create(
                name=name.format(pins),
                description="aka. {}".format(aka.format(pins)) if aka is not None else ""
            )
            t = list(tags)
            t.append(tag_terminals[pins])
            ff.tags.set(t)

    # Passive SMD
    create_ff("2920", "7.4×5.1mm",  tags_passive)
    create_ff("2725", "6.9×6.3mm",  tags_passive)
    create_ff("2512", "6.3×3.2mm",  tags_passive)
    create_ff("2010", "5.0×2.5mm",  tags_passive)
    create_ff("1812", "4.5×6.4mm",  tags_passive)
    create_ff("1806", "4.5×2.6mm",  tags_passive)
    create_ff("1210", "3.2×2.5mm",  tags_passive)
    create_ff("1206", "3.2×1.6mm",  tags_passive)
    create_ff("1008", "2.5×2.0mm",  tags_passive)
    create_ff("0805", "2.0×1.25mm", tags_passive)
    create_ff("0603", "1.6×0.8mm",  tags_passive)
    create_ff("0402", "1.0×0.5mm",  tags_passive)
    create_ff("0201", "0.6×0.3mm",  tags_passive)

    # Tantalum SMD
    create_ff("EIA 2012-12", "Kemet R, AVX R, 2.0×1.3×1.2mm", tags_tantalum)
    create_ff("EIA 3216-10", "Kemet I, AVX K, 3.2×1.6×1.0mm", tags_tantalum)
    create_ff("EIA 3216-12", "Kemet S, AVX S, 3.2×1.6×1.0mm", tags_tantalum)
    create_ff("EIA 3216-18", "Kemet A, AVX A, 3.2×1.8×1.8mm", tags_tantalum)
    create_ff("EIA 3528-12", "Kemet T, AVX T, 3.5×1.2×1.2mm", tags_tantalum)
    create_ff("EIA 3528-21", "Kemet B, AVX B, 3.5×2.1×2.1mm", tags_tantalum)
    create_ff("EIA 6032-15", "Kemet U, AVX W, 6.0×1.5×1.5mm", tags_tantalum)
    create_ff("EIA 6032-28", "Kemet C, AVX C, 6.0×2.8×2.8mm", tags_tantalum)
    create_ff("EIA 7260-38", "Kemet E, AVX V, 7.2×3.8×3.8mm", tags_tantalum)
    create_ff("EIA 7343-20", "Kemet V, AVX Y, 7.3×4.3×2.0mm", tags_tantalum)
    create_ff("EIA 7343-31", "Kemet D, AVX D, 7.3×4.3×3.1mm", tags_tantalum)
    create_ff("EIA 7343-43", "Kemet X, AVX E, 7.3×4.3×4.3mm", tags_tantalum)

    # Electrolyte SMD
    create_ff("Cornell A", "3.3×3.3×5.5mm", tags_electrolytic)
    create_ff("Panasonic B", "4.3×4.3×6.1mm", tags_electrolytic)
    create_ff("Chemi-Con D", "4.3×4.3×5.7mm", tags_electrolytic)
    create_ff("Panasonic C", "5.3×5.3×6.1mm", tags_electrolytic)
    create_ff("Chemi-Con E", "5.3×5.3×5.7mm", tags_electrolytic)
    create_ff("Panasonic D", "6.6×6.6×6.1mm", tags_electrolytic)
    create_ff("Chemi-Con F", "6.6×6.6×5.7mm", tags_electrolytic)
    create_ff("Panasonic E/F", "8.3×8.3×6.5mm", tags_electrolytic)
    create_ff("Chemi-Con H", "8.3×8.3×6.5mm", tags_electrolytic)
    create_ff("Panasonic G", "10.3×10.3×10.5mm", tags_electrolytic)
    create_ff("Chemi-Con J", "10.3×10.3×10.5mm", tags_electrolytic)
    create_ff("Chemi-Con K", "13.0×13.0×14.0mm", tags_electrolytic)
    create_ff("Panasonic H", "13.5×13.5×14.0mm", tags_electrolytic)
    create_ff("Panasonic J", "17×17×17mm", tags_electrolytic)
    create_ff("Chemi-Con L", "17×17×17mm", tags_electrolytic)
    create_ff("Panasonic K", "19×19×17mm", tags_electrolytic)
    create_ff("Chemi-Con M", "19×19×17mm", tags_electrolytic)

    # Diodes
    create_ff("SOD-80C", "3.5×⌀1.5mm", tags_diode)
    create_ff("SOD-123", "2.65×1.6×1.35mm", tags_diode)
    create_ff("SOD-128", "3.8×2.5×1.1mm", tags_diode)
    create_ff("SOD-323", "1.7×1.25×1.1mm", tags_diode)
    create_ff("SOD-523", "1.2×0.8×0.65mm", tags_diode)
    create_ff("SOD-723", "1.4×0.6×0.65mm", tags_diode)
    create_ff("SOD-923", "0.8×0.6×0.4mm", tags_diode)

    create_ff("MicroMELF", "2.2x⌀1.1mm", smd_2_terminal)
    create_ff("MiniMELF", "aka. SOD-80 or DO-213AA, 3.6x⌀1.4mm", smd_2_terminal)
    create_ff("MELF", "aka. SOD-106 or DO-213AB, 5.8x⌀2.2mm", smd_2_terminal)

    create_ff("DO-214AA", "SMD, Diode, 5.4×3.6×2.65mm", tags_diode)
    create_ff("DO-214AB", "SMD, Diode, 7.95×5.9×2.25mm", tags_diode)
    create_ff("DO-214AC", "SMD, Diode, 5.2×2.6×2.15mm", tags_diode)

    # SOT 3 terminals
    create_ff("SOT-23-3", "2.92×1.3×1.12mm", [tag_smd, tag_chip, tag_terminals[3]])
    create_ff("SOT-223-3", "", [tag_smd, tag_chip, tag_terminals[3]])
    create_ff("SOT-323", "2.0×1.25×1.1mm", [tag_smd, tag_chip, tag_terminals[3]])
    create_ff("SOT-416", "1.6×0.8×0.9mm", [tag_smd, tag_chip, tag_terminals[3]])
    create_ff("SOT-663", "2.6×1.2×0.6mm", [tag_smd, tag_chip, tag_terminals[3]])
    create_ff("SOT-723", "1.2×0.8×0.55mm", [tag_smd, tag_chip, tag_terminals[3]])
    create_ff("SOT-883", "1.0×0.6×0.5mm", [tag_smd, tag_chip, tag_terminals[3]])

    # SOT 4 terminals
    create_ff("SOT-89", "4.5×2.5×1.5mm", [tag_smd, tag_chip, tag_terminals[4]])
    create_ff("SOT-143", "2.9×1.3×1.22mm", [tag_smd, tag_chip, tag_terminals[4]])
    create_ff("SOT-223", "6.5×3.5×1.8mm", [tag_smd, tag_chip, tag_terminals[4]])

    # Power transistors/mosfets
    create_ff("TO-252", "aka. DPAK, SOT-428, 6.5×10.0×2.2mm", [
        tag_smd,
        tag_chip,
        tag_power_package,
        tag_terminals[3],
        tag_terminals[5]
    ])
    create_ff("TO-263", "aka. D2PAK, SOT-404", [
        tag_smd,
        tag_chip,
        tag_power_package,
        tag_terminals[3],
        tag_terminals[5],
        tag_terminals[6],
        tag_terminals[7],
        tag_terminals[8],
        tag_terminals[9]
    ])
    create_ff("TO-268", "aka. D3PAK", [tag_smd, tag_chip, tag_power_package, tag_terminals[3]])

    # SOT 5 terminals
    create_ff("SOT-23-5", "2.92×1.3×1.12mm", [tag_smd, tag_chip, tag_terminals[5]])
    create_ff("SOT-353", "2.0×1.25×0.95mm", [tag_smd, tag_chip, tag_terminals[5]])
    create_ff("SOT-665", "1.6×1.6×0.55mm", [tag_smd, tag_chip, tag_terminals[5]])
    create_ff("SOT-891", "1.0×1.0×0.5mm", [tag_smd, tag_chip, tag_terminals[5]])
    create_ff("SOT-953", "1.0×0.8×0.5mm", [tag_smd, tag_chip, tag_terminals[5]])

    # 6 terminals
    create_ff("SOT-23-6", "2.92×1.3×1.12mm", [tag_smd, tag_chip, tag_terminals[6]])
    create_ff("SOT-363", "2.0×1.25×0.95mm", [tag_smd, tag_chip, tag_terminals[6]])
    create_ff("SOT-563", "1.6×1.2×0.6mm", [tag_smd, tag_chip, tag_terminals[6]])
    create_ff("SOT-666", "1.6×1.2×0.6mm", [tag_smd, tag_chip, tag_terminals[6]])
    create_ff("SOT-886", "1.45×1.0×0.5mm", [tag_smd, tag_chip, tag_terminals[6]])
    create_ff("SOT-963", "1.0×1.0×0.5mm", [tag_smd, tag_chip, tag_terminals[6]])
    create_ff("SOT-1115", "1.0×0.9×0.35mm", [tag_smd, tag_chip, tag_terminals[6]])
    create_ff("SOT-1202", "1.0×1.0×0.35mm", [tag_smd, tag_chip, tag_terminals[6]])
    create_ff("TSOP-6", "", [tag_smd, tag_chip, tag_terminals[6]])

    # More than 6 terminals
    create_ff("MSOP-8", "3.0×3.0mm", [tag_smd, tag_chip, tag_terminals[8], tag_pin_spacing['0.65']])
    create_ff("MSOP-10", "3.0×3.0mm", [tag_smd, tag_chip, tag_terminals[10], tag_pin_spacing['0.5']])
    create_ff("MSOP-12", "3.0×4.0mm", [tag_smd, tag_chip, tag_terminals[12], tag_pin_spacing['0.65']])
    create_ff("MSOP-16", "3.0×4.0mm", [tag_smd, tag_chip, tag_terminals[16], tag_pin_spacing['0.5']])

    create_ff("DFN-8", "", [tag_smd, tag_chip, tag_terminals[8], tag_pin_spacing['1.27']])
    create_ff("LGA-24", "", [tag_smd, tag_chip, tag_terminals[24]])

    create_chip("SOIC-{}", 8, 40, aka="SO-{}", tags=[tag_smd, tag_pin_spacing['1.27']])
    create_chip("TSOP-{}", 8, 40, tags=[tag_smd, tag_pin_spacing['0.5']])
    create_chip("SSOP-{}-0.635", 8, 40, tags=[tag_smd, tag_pin_spacing['0.635']])
    create_chip("SSOP-{}-0.65", 8, 40, tags=[tag_smd, tag_pin_spacing['0.65']])
    create_chip("SSOP-{}-0.8", 8, 40, tags=[tag_smd, tag_pin_spacing['0.8']])
    create_chip("TSSOP-{}-0.5", 8, 40, tags=[tag_smd, tag_pin_spacing['0.5']])
    create_chip("TSSOP-{}-0.65", 8, 40, tags=[tag_smd, tag_pin_spacing['0.65']])
    create_chip("QSOP-{}", 8, 40, tags=[tag_smd, tag_pin_spacing['0.635']])
    create_chip("VSOP-{}-0.4", 8, 40, tags=[tag_smd, tag_pin_spacing['0.4']])
    create_chip("VSOP-{}-0.5", 8, 40, tags=[tag_smd, tag_pin_spacing['0.5']])
    create_chip("VSOP-{}-0.65", 8, 40, tags=[tag_smd, tag_pin_spacing['0.65']])
    create_chip("QFP-{}", 32, 64, tags=[tag_smd], sides=4)
    create_ff("QFP-128", "", [tag_smd, tag_chip, tag_terminals[128]])
    create_chip("LQFP-{}", 32, 64, tags=[tag_smd], sides=4)
    create_ff("LQFP-128", "", [tag_smd, tag_chip, tag_terminals[128]])
    create_chip("TQFP-{}", 32, 64, tags=[tag_smd], sides=4)
    create_ff("TQFP-128", "", [tag_smd, tag_chip, tag_terminals[128]])
    create_chip("QFN-{}", 32, 64, tags=[tag_smd], sides=4)
    create_ff("QFN-128", "", [tag_smd, tag_chip, tag_terminals[128]])

    # THT
    create_chip("DIP-{}-0.3", 8, 40, tags=[tag_smd, tag_imperial, tag_pin_spacing['2.54'], tag_row_spacing_7_62])
    create_chip("DIP-{}-0.6", 8, 40, tags=[tag_smd, tag_imperial, tag_pin_spacing['2.54'], tag_row_spacing_15_24])
    create_chip("SDIP-{}-0.3", 8, 40, tags=[tag_smd, tag_imperial, tag_pin_spacing['1.78'], tag_row_spacing_7_62])
    create_chip("SDIP-{}-0.6", 8, 40, tags=[tag_smd, tag_imperial, tag_pin_spacing['1.78'], tag_row_spacing_15_24])

    # THT, Small pin counts
    create_ff("TO-3", "mostly power transistors", [tag_tht, tag_terminals[3], tag_panel_mount, tag_metal_can])
    create_ff("TO-5", "mostly transistors, 6.3×⌀8.9mm", [tag_tht, tag_terminals[3], tag_metal_can])
    create_ff("TO-18", "small signal transistors, metal version of TO-92", [tag_tht, tag_terminals[3], tag_metal_can])
    create_ff("TO-66", "mostly power transistors, smaller version of TO-3", [
        tag_tht,
        tag_terminals[3],
        tag_panel_mount,
        tag_metal_can
    ])
    create_ff("TO-92", "", [tag_tht, tag_terminals[3], tag_plastic_package, tag_pin_spacing['1.27']])
    create_ff("SOD-70", "2 terminal version of TO-92, used in 5mm LED", [
        tag_tht,
        tag_polarized,
        tag_terminals[2],
        tag_plastic_package,
        tag_pin_spacing['2.54']
    ])
    create_ff("TO-126", "aka. SOT-32, with mounting hole for heatsink", [
        tag_tht,
        tag_terminals[3],
        tag_plastic_package,
        tag_power_package,
        tag_pin_spacing['2.54']
    ])
    create_ff("TO-220", "with metal backing, mounting hole in tab", [
        tag_tht,
        tag_terminals[3],
        tag_plastic_package,
        tag_power_package,
        tag_pin_spacing['2.54']
    ])
    create_ff("I-PAK", "mostly power mosfets", [
        tag_tht,
        tag_terminals[3],
        tag_plastic_package,
        tag_power_package,
        tag_pin_spacing['2.29']
    ])

    # THT, diodes
    create_ff("DO-7", "mostly germanium", [tag_tht, tag_polarized, tag_terminals[2], tag_diode])
    create_ff("DO-35", "aka. SOD-27, signal diode, 3.05 to 5.08 × ⌀1.53 to ⌀2.28 mm", [
        tag_tht,
        tag_terminals[2],
        tag_polarized,
        tag_diode
    ])
    create_ff("DO-41", "aka. SOD-66, rectifier diode, 4.07 to 5.20 × ⌀2.04 to ⌀2.71 mm", [
        tag_tht,
        tag_terminals[2],
        tag_polarized,
        tag_diode
    ])

    # THT, misc
    create_ff("HC49", "HC49 quartz crystal package, comes in 2 heights", [tag_tht, tag_terminals[2]])
    create_ff("PG-SSO-3-2", "Infineon hall effect sensors", [tag_tht, tag_terminals[3], tag_pin_spacing['1.27']])
    create_ff("LED 5", "5mm LED", [tag_tht, tag_polarized, tag_terminals[2], tag_pin_spacing['2.54']])
    create_ff("LED 3", "3mm LED", [tag_tht, tag_polarized, tag_terminals[2], tag_pin_spacing['1.27']])

    # THT Raster
    create_ff("RM 1.27", "", [tag_tht, tag_pin_spacing['1.27']])
    create_ff("RM 2", "", [tag_tht, tag_pin_spacing['2.0']])
    create_ff("RM 2.54", "", [tag_tht, tag_pin_spacing['2.54']])
    create_ff("RM 3.5", "", [tag_tht, tag_pin_spacing['3.5']])
    create_ff("RM 7.5", "", [tag_tht, tag_pin_spacing['7.5']])
    create_ff("RM 5", "", [tag_tht, tag_pin_spacing['5.0']])
    create_ff("RM 5.08", "", [tag_tht, tag_pin_spacing['5.08']])

    # TODO:
    # - Arrow (broken webpage)

    Distributor.objects.create(
        name="Reichelt",
        description="Reichelt Elektronik",
        web_link="https://www.reichelt.de",
        search_link="https://www.reichelt.de/index.html?ACTION=446&LA=0&nbc=1&q={}",
        phone="+49 4422 955-333",
        email="info@reichelt.de",
        icon=ImageFile(open('inventory/static/inventory/img/reichelt.png', 'rb'))
    ).tags.set([tag_germany])
    Distributor.objects.create(
        name="Amazon",
        description="Amazon DE",
        web_link="https://amazon.de",
        search_link="https://www.amazon.de/s?k={}",
        icon=ImageFile(open('inventory/static/inventory/img/amazon.png', 'rb'))
    ).tags.set([tag_germany])
    Distributor.objects.create(
        name="AZ Delivery",
        description="AZ Delivery Deutschland",
        web_link="https://az-delivery.de",
        search_link="https://az-delivery.de/de/search?type=product&q={}*",
        phone="+49 991 99927827",
        email="info@az-delivery.com",
        icon=ImageFile(open('inventory/static/inventory/img/azdelivery.png', 'rb'))
    ).tags.set([tag_germany])
    Distributor.objects.create(
        name="DevElektro",
        description="DevElektro, consumer branch of Farnell",
        web_link="https://www.develektro.com",
        search_link="https://www.develektro.com/navi.php?qs={}&search=",
        phone=" +49 35754 794780",
        email="info@develektro.com",
        icon=ImageFile(open('inventory/static/inventory/img/develektro.png', 'rb'))
    ).tags.set([tag_germany])
    Distributor.objects.create(
        name="Watterott",
        description="Watterott electronic",
        web_link="https://shop.watterott.com",
        search_link="https://shop.watterott.com/navi.php?qs={}&search=",
        phone="+49 3605 578010",
        email="info@watterott.com",
        icon=ImageFile(open('inventory/static/inventory/img/watterott.png', 'rb'))
    ).tags.set([tag_germany])
    Distributor.objects.create(
        name="Ebay",
        description="Ebay DE",
        web_link="https://www.ebay.de/",
        search_link="https://www.ebay.de/sch/i.html?_nkw={}&_sacat=0",
        icon=ImageFile(open('inventory/static/inventory/img/ebay.png', 'rb'))
    ).tags.set([tag_germany])
    Distributor.objects.create(
        name="Farnell",
        description="Farnell DE",
        web_link="https://de.farnell.com/",
        search_link="https://de.farnell.com/w/search/prl/ergebnisse?st={}",
        phone="+49 89 61 39 39 79",
        email="verkauf@farnell.com",
        icon=ImageFile(open('inventory/static/inventory/img/farnell.png', 'rb'))
    ).tags.set([tag_germany])
    Distributor.objects.create(
        name="Mouser",
        description="Mouser DE",
        web_link="https://www.mouser.de/",
        search_link="https://www.mouser.de/Search/Refine?Keyword={}",
        phone="+49 89 520 462 110 ",
        email="muenchen@mouser.com",
        icon=ImageFile(open('inventory/static/inventory/img/mouser.png', 'rb'))
    ).tags.set([tag_germany])
    Distributor.objects.create(
        name="Digikey",
        description="Digikey DE",
        web_link="https://www.digikey.de/",
        search_link="https://www.digikey.de/products/de?keywords={}",
        phone="+49 30 915 884 91",
        email="eu.support@digikey.com",
        icon=ImageFile(open('inventory/static/inventory/img/digikey.png', 'rb'))
    ).tags.set([tag_germany])
    Distributor.objects.create(
        name="Conrad",
        description="Conrad DE",
        web_link="https://www.conrad.de/",
        search_link="https://www.conrad.de/de/search.html?search={}",
        phone="+49 9604 40 87 87",
        email="kundenservice@conrad.de",
        icon=ImageFile(open('inventory/static/inventory/img/conrad.png', 'rb'))
    ).tags.set([tag_germany])
    Distributor.objects.create(
        name="Adafruit",
        description="Adafruit Industries",
        web_link="https://www.adafruit.com/",
        search_link="https://www.adafruit.com/?q={}&sort=BestMatch",
        icon=ImageFile(open('inventory/static/inventory/img/adafruit.png', 'rb'))
    ).tags.set([tag_usa])
    Distributor.objects.create(
        name="EBV Elektronik",
        description="AVNet Germany",
        web_link="https://www.avnet.com/wps/portal/ebv/",
        search_link="https://www.avnet.com/shop/emea/search/{}",
        phone="+49 8121 774 0",
        icon=ImageFile(open('inventory/static/inventory/img/ebv.png', 'rb'))
    ).tags.set([tag_germany])
    Distributor.objects.create(
        name="Pollin",
        description="Pollin Elektronik",
        web_link="https://www.pollin.de/",
        search_link="https://www.pollin.de/search?query={}",
        phone="+49 8403 920 920",
        email="service@pollin.de",
        icon=ImageFile(open('inventory/static/inventory/img/pollin.png', 'rb'))
    ).tags.set([tag_germany])
    Distributor.objects.create(
        name="Maplin",
        description="Maplin UK",
        web_link="https://www.maplin.co.uk/",
        search_link="https://www.maplin.co.uk/catalogsearch/result/?q={}",
        icon=ImageFile(open('inventory/static/inventory/img/maplin.png', 'rb'))
    ).tags.set([tag_uk])
    Distributor.objects.create(
        name="Pimoroni",
        description="Pimoroni",
        web_link="https://shop.pimoroni.com/",
        search_link="https://shop.pimoroni.com/?q={}",
        icon=ImageFile(open('inventory/static/inventory/img/pimoroni.png', 'rb'))
    ).tags.set([tag_uk])
    Distributor.objects.create(
        name="Rapid",
        description="Rapid Elektronics, Conrad outlet",
        web_link="https://www.rapidonline.com/",
        search_link="https://www.rapidonline.com/Catalogue/Search?Query={}",
        email="sales@rapidonline.com",
        icon=ImageFile(open('inventory/static/inventory/img/rapid.png', 'rb'))
    ).tags.set([tag_uk])
    Distributor.objects.create(
        name="RS Components",
        description="RS Components DE",
        web_link="https://de.rs-online.com/web/",
        search_link="https://de.rs-online.com/web/c/?sra=oss&r=t&searchTerm={}",
        phone="+49 69 5800 14 234",
        email="rs-gmbh@rsonline.de",
        icon=ImageFile(open('inventory/static/inventory/img/rs.png', 'rb'))
    ).tags.set([tag_germany])
    Distributor.objects.create(
        name="Sparkfun",
        description="Sparkfun",
        web_link="https://www.sparkfun.com/",
        search_link="https://www.sparkfun.com/search/results?term={}",
        email="support@sparkfun.com",
        icon=ImageFile(open('inventory/static/inventory/img/sparkfun.png', 'rb'))
    ).tags.set([tag_usa])

    Layout.objects.bulk_create([
        Layout(
            name="SMD Box-ALL",
            description="AideTek SMD Box-All 144 compartments",
            data=[
                [[1] * 12] * 6
            ] * 2
        ),
        Layout(
            name="Pollin Sorter",
            description="Pollin.de 17 compartments sorting box",
            data=[
                [1, 1, 1, 1, 1, 1],
                [2, 1, 1, 1, 1, 1],
                [   1, 1, 1, 1, 1]  # noqa: E201
            ]
        ),

        #
        # Raaco
        #
        Layout(
            name="Raaco 1260-00",
            description="Raaco 150 Series, 60 compartments",
            data=[
                [3] * 5
            ] * 12,
            template_name='raaco-even'
        ),
        Layout(
            name="Raaco 1248-01",
            description="Raaco 150 Series, 48 compartments",
            data=[
                [3] * 4
            ] * 12,
            template_name='raaco-even'
        ),
        Layout(
            name="Raaco 1224-02",
            description="Raaco 150 Series, 24 compartments",
            data=[
                [3] * 3
            ] * 8,
            template_name='raaco-even'
        ),
        Layout(
            name="Raaco 1208-03",
            description="Raaco 150 Series, 8 compartments",
            data=[
                [3] * 8
            ],
            template_name='raaco-simple'
        ),
        Layout(
            name="Raaco 1216-04",
            description="Raaco 150 Series, 16 compartments",
            data=[
                [3] * 2
            ] * 8,
            template_name='raaco-even'
        ),
        Layout(
            name="Raaco 1240-123",
            description="Raaco 150 Series, 16 compartments",
            data=[
                [3, 3, 3, 3],
                [3, 3, 3, 3],
                [3, 3, 3, 3],
                [3, 3, 3, 3],
                [3, 3, 3, 3],
                [3, 3, 3, 3],
                [3, 3, 3, 3],
                [3, 3, 3, 3],
                [3, 3, 3, 3],
                [3, 3, 3],
                [   3   ]  # noqa: E201, E202
            ]
        ),
        Layout(
            name="Raaco 945-00",
            description="Raaco 150 Series, 45 compartments",
            data=[
                [3] * 5
            ] * 9,
            template_name='raaco-even'
        ),
        Layout(
            name="Raaco 936-01",
            description="Raaco 150 Series, 36 compartments",
            data=[
                [3] * 4
            ] * 9,
            template_name='raaco-even'
        ),
        Layout(
            name="Raaco 918-02",
            description="Raaco 150 Series, 18 compartments",
            data=[
                [3] * 3
            ] * 6,
            template_name='raaco-even'
        ),
        Layout(
            name="Raaco 906-03",
            description="Raaco 150 Series, 6 compartments",
            data=[
                [3] * 6
            ],
            template_name='raaco-simple'
        ),
        Layout(
            name="Raaco 928-123",
            description="Raaco 150 Series, 6 compartments",
            data=[
                [3, 3, 3, 3],
                [3, 3, 3, 3],
                [3, 3, 3, 3],
                [3, 3, 3, 3],
                [3, 3, 3, 3],
                [3, 3, 3, 3],
                [3, 3, 3],
                [3]
            ]
        ),
        Layout(
            name="Raaco 630-00",
            description="Raaco 150 Series, 30 compartments",
            data=[
                [3] * 5
            ] * 6,
            template_name='raaco-even'
        ),
        Layout(
            name="Raaco 624-01",
            description="Raaco 150 Series, 24 compartments",
            data=[
                [3] * 4
            ] * 6,
            template_name='raaco-even'
        ),
        Layout(
            name="Raaco 612-02",
            description="Raaco 150 Series, 12 compartments",
            data=[
                [3] * 3
            ] * 4,
            template_name='raaco-even'
        ),
        Layout(
            name="Raaco 616-123",
            description="Raaco 150 Series, 16 compartments",
            data=[
                [3, 3, 3, 3],
                [3, 3, 3, 3],
                [3, 3, 3, 3],
                [3, 3, 3],
                [3]
            ]
        ),
        Layout(
            name="Raaco 250/24-1",
            description="Raaco 250 Series, 24 compartments",
            data=[
                [3] * 4,
            ] * 6,
            template_name='raaco-even'
        ),
        Layout(
            name="Raaco 250/8-2",
            description="Raaco 250 Series, 8 compartments",
            data=[
                [3] * 2,
            ] * 4,
            template_name='raaco-even'
        ),
        Layout(
            name="Raaco 250/6-3",
            description="Raaco 250 Series, 6 compartments",
            data=[
                [3] * 6,
            ],
            template_name='raaco-simple'
        ),

        #
        # Stanley
        #
        Layout(
            name="Stanley Sorter 1",
            description="Stanley 14011 Organizer OPP 11\", 10 compartments, every compartment",
            data=[
                [1, 1, 1, 1, 1, 1],
                [1, 1, 1, 1, 1, 1],
                [1, 1,       1, 1]
            ]
        ),
        Layout(
            name="Stanley Sorter 2",
            description="Stanley 14011 Organizer OPP 11\", 10 compartments, 2 wide compartments",
            data=[
                [2, 2, 2],
                [2, 2, 2],
                [2,    2]
            ]
        ),

        #
        # Ikea
        #
        Layout(
            name="Ikea Glis",
            description="Ikea Sorter, 34x21cm, 5 compartments",
            data=[
                [2,       3],
                [   1, 1, 1]  # noqa: E201
            ]
        ),
        Layout(
            name="Ikea Samla 5L",
            description="Ikea Samla box, 28x20x14cm",
            data=[
                [5]
            ],
            template_name='ikea-samla'
        ),
        Layout(
            name="Ikea Samla 11L",
            description="Ikea Samla box, 39x28x14cm",
            data=[
                [11]
            ],
            template_name='ikea-samla'
        ),
        Layout(
            name="Ikea Samla 22L",
            description="Ikea Samla box, 39x28x28cm",
            data=[
                [22]
            ],
            template_name='ikea-samla'
        ),
        Layout(
            name="Ikea Samla 45L",
            description="Ikea Samla box, 57x39x28cm",
            data=[
                [45]
            ],
            template_name='ikea-samla'
        ),
        Layout(
            name="Ikea Samla 55L",
            description="Ikea Samla box, 79x57x18cm",
            data=[
                [55]
            ],
            template_name='ikea-samla'
        ),
        Layout(
            name="Ikea Samla 65L",
            description="Ikea Samla box, 57x39x42cm",
            data=[
                [65]
            ],
            template_name='ikea-samla'
        ),
        Layout(
            name="Ikea Samla 135L",
            description="Ikea Samla box, 79x57x43cm",
            data=[
                [135]
            ],
            template_name='ikea-samla'
        )
    ])


class Migration(migrations.Migration):

    dependencies = [
        ('inventory', '0001_initial'),
    ]

    operations = [
        migrations.RunPython(default_data)
    ]
