# Generated by Django 3.2.3 on 2022-02-15 21:29

from django.db import migrations

from config import DOMAINCONF

price_info_list = [
    {
        "name": "1k_times",
        "title": "1k_times",
        "description": "1k_times",
        "price": 2500,
        "price_type": 1,
        "package_size": 1000,
        "download_count_gift": 100,
        "is_enable": True,
    },
    {
        "name": "10k_times",
        "title": "10k_times",
        "description": "10k_times",
        "price": 22000,
        "price_type": 1,
        "package_size": 10000,
        "download_count_gift": 800,
        "is_enable": True,
    },
    {
        "name": "100k_times",
        "title": "100k_times",
        "description": "100k_times",
        "price": 200000,
        "price_type": 1,
        "package_size": 100000,
        "download_count_gift": 8000,
        "is_enable": True,
    },
    {
        "name": "storage_3_month",
        "title": "三个月",
        "description": "三个月",
        "price": 3,
        "price_type": 2,
        "package_size": 3,
        "download_count_gift": 0,
        "is_enable": True,
    }, {
        "name": "storage_6_month",
        "title": "半年",
        "description": "半年",
        "price": 6,
        "price_type": 2,
        "package_size": 6,
        "download_count_gift": 0,
        "is_enable": True,
    }, {
        "name": "storage_12_month",
        "title": "一年",
        "description": "一年",
        "price": 12,
        "price_type": 2,
        "package_size": 12,
        "download_count_gift": 0,
        "is_enable": True,
    }, {
        "name": "storage_24_month",
        "title": "两年",
        "description": "两年",
        "price": 24,
        "price_type": 2,
        "package_size": 24,
        "download_count_gift": 0,
        "is_enable": True,
    }, {
        "name": "storage_36_month",
        "title": "三年",
        "description": "三年",
        "price": 36,
        "price_type": 2,
        "package_size": 36,
        "download_count_gift": 0,
        "is_enable": True,
    }

]
WEB_DOMAIN = DOMAINCONF.WEB_DOMAIN.split('//')[1]
domain_cname_info_list = [
    {
        "domain_record": WEB_DOMAIN,
        "ip_address": WEB_DOMAIN,
        "is_enable": True,
        "is_system": True,
        "is_https": True if DOMAINCONF.WEB_DOMAIN.startswith('https') else False,
        "description": f"默认下载页域名 {WEB_DOMAIN}",
    },
]


def add_default_price(apps, schema_editor):
    for price in price_info_list:
        price_model = apps.get_model('api', 'Price')
        price_model.objects.create(**price)


def add_default_domain_cname(apps, schema_editor):
    for domain_cname_info in domain_cname_info_list:
        domain_cname_info_model = apps.get_model('api', 'DomainCnameInfo')
        domain_cname_info_model.objects.create(**domain_cname_info)


class Migration(migrations.Migration):
    dependencies = [
        ('api', '0001_initial'),
    ]

    operations = [
        migrations.RunPython(add_default_price),
        migrations.RunPython(add_default_domain_cname)
    ]
