from time import sleep

data = [
    {
        "id": 1,
        "name": "Mobiuz",
        "color": "mobiuz",
        "url": "http:\/\/mobi.uz\/",
        "connect": "0890",
        "balance": "*100#",
        "slogan": "Raqamli imkoniyat sari!"
    },
    {
        "id": 2,
        "name": "Uzmobile",
        "color": "uzmobile",
        "url": "https:\/\/cabinet.uztelecom.uz\/ps\/scc\/login.php",
        "connect": "1099",
        "balance": "*107#",
        "slogan": "Ishonchli mobil aloqa operatori!"
    },
    {
        "id": 3,
        "name": "Ucell",
        "color": "ucell",
        "url": "http:\/\/ucell.uz\/",
        "connect": "8123",
        "balance": "*100#",
        "slogan": "Hayotni yaxshilik sari o'zgartirib!"
    },
    {
        "id": 4,
        "name": "Beeline",
        "color": "beeline",
        "url": "http:\/\/beeline.uz\/",
        "connect": "0611",
        "balance": "*102#",
        "slogan": "Yetakchi. Ishonchli! Innovatsion!"
    },
    {
        "id": 5,
        "name": "011200189",
        "color": "17787",
        "url": "23631",
        "connect": "011200235",
        "balance": "82121",
        "slogan": "23631"
    }
]

xizmatlar = [
    {
        'title': 'Internet',
        'desc': 'Toplamlar'
    },

    {
        'title': 'Tariflar',
        'desc': 'tariflar'
    },

    {'title': 'SMS',
     'desc': "to'plamlar"
     },
    {
        'title': 'Qadiqa',
     'desc': "to'plamlar"
    },

    {
        "title": "USSD",
        "desc": "kodlar"
    },

    {'title': "Qo'shimcha ",
     'desc': 'xizmatlar'}
]

kats = [
    {
        "id": 1,
        "title": "Oylik",
        "companyId": 1,
        "type": 1,
        "dataType": 0
    },
    {
        "id": 3,
        "title": "Kunlik",
        "companyId": 1,
        "type": 1,
        "dataType": 1
    },
    {
        "id": 4,
        "title": "Tungi",
        "companyId": 1,
        "type": 1,
        "dataType": 2
    },
    {
        "id": 5,
        "title": "Faol",
        "companyId": 1,
        "type": 2,
        "dataType": 0
    },
    {
        "id": 6,
        "title": "Yillik",
        "companyId": 1,
        "type": 2,
        "dataType": 1
    },
    {
        "id": 8,
        "title": "Fresh",
        "companyId": 1,
        "type": 2,
        "dataType": 3
    },
    {
        "id": 9,
        "title": "Oy",
        "companyId": 1,
        "type": 3,
        "dataType": 0
    },
    {
        "id": 10,
        "title": "Gap ko'p",
        "companyId": 1,
        "type": 3,
        "dataType": 1
    },
    {
        "id": 11,
        "title": "Oy",
        "companyId": 1,
        "type": 4,
        "dataType": 0
    },
    {
        "id": 12,
        "title": "Sms onnet",
        "companyId": 1,
        "type": 4,
        "dataType": 1
    },
    {
        "id": 13,
        "title": "Ussd kodlar",
        "companyId": 1,
        "type": 5,
        "dataType": 0
    },
    {
        "id": 14,
        "title": "Xizmatlar",
        "companyId": 1,
        "type": 6,
        "dataType": 0
    },
    {
        "id": 15,
        "title": "Pullik xizmatlar",
        "companyId": 1,
        "type": 6,
        "dataType": 1
    },
    {
        "id": 16,
        "title": "Oy",
        "companyId": 2,
        "type": 1,
        "dataType": 0
    },
    {
        "id": 17,
        "title": "Kun",
        "companyId": 2,
        "type": 1,
        "dataType": 1
    },
    {
        "id": 18,
        "title": "Tun",
        "companyId": 2,
        "type": 1,
        "dataType": 2
    },
    {
        "id": 24,
        "title": "Units",
        "companyId": 2,
        "type": 2,
        "dataType": 1
    },
    {
        "id": 25,
        "title": "3 Oylik",
        "companyId": 2,
        "type": 2,
        "dataType": 2
    },
    {
        "id": 27,
        "title": "Daqiqalar",
        "companyId": 2,
        "type": 3,
        "dataType": 0
    },
    {
        "id": 28,
        "title": "Konstruktor",
        "companyId": 2,
        "type": 3,
        "dataType": 1
    },
    {
        "id": 29,
        "title": "Oy",
        "companyId": 2,
        "type": 4,
        "dataType": 1
    },
    {
        "id": 30,
        "title": "Kun",
        "companyId": 2,
        "type": 4,
        "dataType": 0
    },
    {
        "id": 31,
        "title": "Xalqaro",
        "companyId": 2,
        "type": 4,
        "dataType": 2
    },
    {
        "id": 32,
        "title": "Konstruktor",
        "companyId": 2,
        "type": 4,
        "dataType": 3
    },
    {
        "id": 33,
        "title": "Ussd kodlar",
        "companyId": 2,
        "type": 5,
        "dataType": 0
    },
    {
        "id": 34,
        "title": "Xizmatlar",
        "companyId": 2,
        "type": 6,
        "dataType": 0
    },
    {
        "id": 35,
        "title": "Pullik xizmatlar",
        "companyId": 2,
        "type": 6,
        "dataType": 1
    },
    {
        "id": 36,
        "title": "Oylik",
        "companyId": 3,
        "type": 1,
        "dataType": 0
    },
    {
        "id": 37,
        "title": "Kunlik",
        "companyId": 3,
        "type": 1,
        "dataType": 1
    },
    {
        "id": 38,
        "title": "Haftalik",
        "companyId": 3,
        "type": 1,
        "dataType": 2
    },
    {
        "id": 39,
        "title": "Tun",
        "companyId": 3,
        "type": 1,
        "dataType": 3
    },
    {
        "id": 43,
        "title": "Modem",
        "companyId": 3,
        "type": 1,
        "dataType": 4
    },
    {
        "id": 44,
        "title": "Tariflar",
        "companyId": 3,
        "type": 2,
        "dataType": 0
    },
    {
        "id": 47,
        "title": "Daqiqalar",
        "companyId": 3,
        "type": 3,
        "dataType": 0
    },
    {
        "id": 48,
        "title": "Oylik",
        "companyId": 3,
        "type": 4,
        "dataType": 0
    },
    {
        "id": 49,
        "title": "Kunlik",
        "companyId": 3,
        "type": 4,
        "dataType": 1
    },
    {
        "id": 50,
        "title": "Xalqaro",
        "companyId": 3,
        "type": 4,
        "dataType": 2
    },
    {
        "id": 51,
        "title": "Ussd kodlar",
        "companyId": 3,
        "type": 5,
        "dataType": 0
    },
    {
        "id": 52,
        "title": "Xizmatlar",
        "companyId": 3,
        "type": 6,
        "dataType": 0
    },
    {
        "id": 53,
        "title": "Pullik xizmatlar",
        "companyId": 3,
        "type": 6,
        "dataType": 1
    },
    {
        "id": 54,
        "title": "Oy",
        "companyId": 4,
        "type": 1,
        "dataType": 0
    },
    {
        "id": 55,
        "title": "Hafta",
        "companyId": 4,
        "type": 1,
        "dataType": 1
    },
    {
        "id": 56,
        "title": "Kun",
        "companyId": 4,
        "type": 1,
        "dataType": 2
    },
    {
        "id": 57,
        "title": "Oy",
        "companyId": 4,
        "type": 2,
        "dataType": 0
    },
    {
        "id": 58,
        "title": "Kun",
        "companyId": 4,
        "type": 2,
        "dataType": 1
    },
    {
        "id": 59,
        "title": "To'plam",
        "companyId": 4,
        "type": 2,
        "dataType": 2
    },
    {
        "id": 60,
        "title": "Daqiqalar",
        "companyId": 4,
        "type": 3,
        "dataType": 0
    },
    {
        "id": 61,
        "title": "Kun",
        "companyId": 4,
        "type": 4,
        "dataType": 0
    },
    {
        "id": 62,
        "title": "Oy",
        "companyId": 4,
        "type": 4,
        "dataType": 1
    },
    {
        "id": 63,
        "title": "Xalqaro",
        "companyId": 4,
        "type": 4,
        "dataType": 2
    },
    {
        "id": 64,
        "title": "Ussd kodlar",
        "companyId": 4,
        "type": 5,
        "dataType": 0
    },
    {
        "id": 65,
        "title": "Xizmatlar",
        "companyId": 4,
        "type": 6,
        "dataType": 0
    },
    {
        "id": 66,
        "title": "Pullik xizmatlar",
        "companyId": 4,
        "type": 6,
        "dataType": 1
    },
    {
        "id": 67,
        "title": "Onnet",
        "companyId": 1,
        "type": 1,
        "dataType": 3
    },
    {
        "id": 68,
        "title": "non-stop",
        "companyId": 2,
        "type": 1,
        "dataType": 7
    },
    {
        "id": 69,
        "title": "Foydali",
        "companyId": 2,
        "type": 1,
        "dataType": 8
    },
    {
        "id": 70,
        "title": "Foydali",
        "companyId": 2,
        "type": 3,
        "dataType": 2
    },
    {
        "id": 71,
        "title": "Foydali",
        "companyId": 4,
        "type": 3,
        "dataType": 1
    },
    {
        "id": 72,
        "title": "Foydali",
        "companyId": 4,
        "type": 4,
        "dataType": 3
    },
    {
        "id": 73,
        "title": "Foydali",
        "companyId": 4,
        "type": 1,
        "dataType": 3
    },
    {
        "id": 74,
        "title": "Milliy",
        "companyId": 2,
        "type": 2,
        "dataType": 4
    },
    {
        "id": 75,
        "title": "Sovg'a",
        "companyId": 2,
        "type": 1,
        "dataType": 9
    },
    {
        "id": 76,
        "title": "Sof",
        "companyId": 3,
        "type": 2,
        "dataType": 3
    },
    {
        "id": 77,
        "title": "Aksiya",
        "companyId": 3,
        "type": 1,
        "dataType": 5
    },
    {
        "id": 78,
        "title": "5G",
        "companyId": 1,
        "type": 1,
        "dataType": 4
    },
    {
        "id": 79,
        "title": "Axborot",
        "companyId": 3,
        "type": 6,
        "dataType": 2
    },
    {
        "id": 80,
        "title": "Kun",
        "companyId": 2,
        "type": 2,
        "dataType": 5
    },
    {
        "id": 81,
        "title": "Doimiy",
        "companyId": 3,
        "type": 2,
        "dataType": 4
    },
    {
        "id": 82,
        "title": "Zo'r",
        "companyId": 4,
        "type": 2,
        "dataType": 3
    },
    {
        "id": 83,
        "title": "Status",
        "companyId": 4,
        "type": 2,
        "dataType": 4
    },
    {
        "id": 84,
        "title": "Yana",
        "companyId": 4,
        "type": 2,
        "dataType": 5
    },
    {
        "id": 85,
        "title": "Ofislarda",
        "companyId": 1,
        "type": 2,
        "dataType": 4
    },
    {
        "id": 86,
        "title": "Arxiv",
        "companyId": 1,
        "type": 2,
        "dataType": 5
    },
    {
        "id": 87,
        "title": "Ofislarda",
        "companyId": 2,
        "type": 2,
        "dataType": 6
    },
    {
        "id": 88,
        "title": "Arxiv",
        "companyId": 2,
        "type": 2,
        "dataType": 7
    },
    {
        "id": 89,
        "title": "Arxiv",
        "companyId": 3,
        "type": 2,
        "dataType": 5
    },
    {
        "id": 90,
        "title": "Ofislarda",
        "companyId": 3,
        "type": 2,
        "dataType": 6
    },
    {
        "id": 91,
        "title": "Barakali",
        "companyId": 2,
        "type": 2,
        "dataType": 8
    },
    {
        "id": 92,
        "title": "Cinema",
        "companyId": 1,
        "type": 6,
        "dataType": 2
    },
    {
        "id": 93,
        "title": "Xotirjam",
        "companyId": 1,
        "type": 2,
        "dataType": 6
    }
]



from rest_framework.views import APIView
from rest_framework.response import Response
from .models import Company, Malumotlar, Foydali, Resource, Universal


class CompanyView(APIView):
    def post(self, request):

        # for comp in data:
        #     Company.objects.create(
        #     name=comp['name'],
        #     slogan = comp['slogan'],
        #     url = comp['url'],
        #     connect = comp['connect'],
        #     color = comp['color'],
        #     icon_url = 'ss'
        #     )
        # for i, xizmat in enumerate(xizmatlar, start=1):
        #     Xizmat.objects.create(
        #         title=xizmat['title'],
        #         desc = xizmat['desc'],
        #         company_id = 5,
        #         sortby = i,
        #         news = 0
        #     )

        # for kat in kats:
        #     Category.objects.create(
        #         title=kat['title'],
        #         xizmat_id = kat['type'],
        #         company_id = kat['companyId'],
        #         sortby = kat['dataType']
        #     )
        #

        import json

        # Opening JSON file
        f = open('common/uni.json')

        # returns JSON object as
        # a dictionary
        unis = json.load(f)

        # Iterating through the json
        # list
        for obj in unis['data']:
            cat = obj['dataTypeId']
            com = obj['companyId']
            t = obj['type']

            if cat == 0:
                cat = 1

            if com == 0:
                com = 1

            if t == 0:
                t = 1

            Company.objects.create(

            )

            sleep(0.005)

        # Closing file
        f.close()


        n = Company.objects.count()

        return Response(data={'n': n}, status=200)


class AddCompany(APIView):
    def get(self, request, *args, **kwargs):

        import json

        # Opening JSON file
        f = open('company.json')

        # returns JSON object as
        # a dictionary
        unis = json.load(f)

        # Iterating through the json
        # list
        for obj in unis['data']:
            Company.objects.create(
                name=obj['name'],
                color = obj['color'],
                url = obj['url'],
                connect = obj['connect'],
                balance = obj['balance'],
                slogan = obj['slogan'],
            )

            # sleep(0.005)

        # Closing file
        f.close()


        return Response(200)


class AddMalumotlar(APIView):
    def get(self, request, *args, **kwargs):

        import json

        # Opening JSON file
        f = open('malumotlar.json')

        # returns JSON object as
        # a dictionary
        unis = json.load(f)

        # Iterating through the json
        # list
        for obj in unis['data']:
            Malumotlar.objects.create(
                info= obj['info'],
                calling =obj['calling'],
                companyId_id = obj['companyId']
            )

            # sleep(0.005)

        # Closing file
        f.close()


        return Response(200)


class AddFoydali(APIView):
    def get(self, request, *args, **kwargs):

        import json

        # Opening JSON file
        f = open('foydali.json')

        # returns JSON object as
        # a dictionary
        unis = json.load(f)

        # Iterating through the json
        # list
        for obj in unis:
            Foydali.objects.create(
                title= obj['title'],
                calling =obj['calling']
            )

            # sleep(0.005)

        # Closing file
        f.close()


        return Response(200)




class AddResource(APIView):
    def get(self, request, *args, **kwargs):

        import json

        # Opening JSON file
        f = open('recourse.json')

        # returns JSON object as
        # a dictionary
        unis = json.load(f)

        # Iterating through the json
        # list
        for obj in unis:
            Resource.objects.create(
                title= obj['title'],
                companyId_id = obj['companyId'],
                type=obj['type'],
                dataType=obj['dataType']
            )

            # sleep(0.005)

        # Closing file
        f.close()


        return Response(200)


class AddUniversal(APIView):
    def get(self, request, *args, **kwargs):

        import json

        # Opening JSON file
        f = open('universal.json')

        # returns JSON object as
        # a dictionary
        unis = json.load(f)

        # Iterating through the json
        # list
        for obj in unis:
            cat = obj['dataTypeId']
            com = obj['companyId']
            t = obj['type']

            if cat == None:
                cat = 1

            if com == 0 or com==None:
                com = 1

            if t == None:
                t = 1
            Universal.objects.create(
                title= obj['title'],
                amount = obj['amount'],
                type = t,
                companyId_id = com,
                dataTypeId = cat,
                connect = obj['connect'],
                allocation = obj['allocation'],
                bookMarks = obj['bookMarks']
            )

            sleep(0.005)

        # Closing file
        f.close()


        return Response(200)