from django.core.management import BaseCommand
from tqdm import tqdm

from store.models import Category, PaymentMethod

category_names = {
    "shoes": "Обувь",
    "outerwear": "Верхняя одежда",
    "underwear": "Нижнее белье",
    "bags": "Сумки",
    "cosmetics": "Косметика",
    "accessories": "Аксессуары",
    "technics": "Техника",
    "watches": "Часы",
    "toys": "Игрушки",
    "home": "Товары для дома",
    "foodndrinks": "Еда и напитки",
    "different": "Другое",
}

payment_methods = {
    "alfa": {
        "name": "Альфабанк",
        "cardnumber": "",
        "requisites": ""
    },
    "ralf": {
        "name": "Райффайзен Банк",
        "cardnumber": "",
        "requisites": ""
    },
    "tink": {
        "name": "Тинькофф",
        "cardnumber": "",
        "requisites": ""
    }
}


class Command(BaseCommand):
    help = ''' Create root categories '''

    def create_categories(self):
        for slug, name in tqdm(category_names.items(), desc="Creating categories"):
            Category.objects.get_or_create(slug=slug, defaults={"name": name})

    def create_payment_types(self):
        for slug, data in tqdm(payment_methods.items(), desc="Creating payment methods"):
            PaymentMethod.objects.get_or_create(slug=slug, defaults=data)

    def handle(self, *args, **kwargs):
        self.create_categories()
        self.create_payment_types()

