from django.core.management.base import BaseCommand

from accounts.models import Role
from common.consts import UserRoles


class Command(BaseCommand):
    help = "Generates default roles"

    def handle(self, *args, **options):
        roles = [
            {
                "name": "ادمین",
                "slug": UserRoles.ADMIN,
            },
            {
                "name": "مشترک",
                "slug": UserRoles.CUSTOMER,
            },
            {
                "name": "مدیر",
                "slug": UserRoles.MANAGER,
            },
            {
                "name": "حسابدار",
                "slug": UserRoles.ACCOUNTANT,
            },
            {
                "name": "پیشخوان",
                "slug": UserRoles.BROKER,
            },
            {
                "name": "نصاب",
                "slug": UserRoles.INSTALLER,
            },
            {
                "name": "کارشناس امور",
                "slug": UserRoles.REGIONAL_WATER_AUTHORITY,
            },
            {
                "name": "مدیر منابع آب",
                "slug": UserRoles.WATER_RESOURCE_MANAGER,
            },
            {
                "name": "ستاد آب‌منطقه‌ای",
                "slug": UserRoles.HEADQUARTER,
            },
        ]

        for role in roles:
            Role.objects.get_or_create(name=role['name'], slug=role['slug'].value)
