from django.core.management.base import BaseCommand
import pycountry
from config.models import Country


class Command(BaseCommand):
    help = "Populate the Country model with data from pycountry"

    def handle(self, *args, **kwargs):
        for country in pycountry.countries:
            Country.objects.get_or_create(
                name=country.name,
                code=country.alpha_2,
                alpha_3=getattr(country, 'alpha_3', None),
                numeric=getattr(country, 'numeric', None),
                official_name=getattr(country, 'official_name', None),
            )
        self.stdout.write(self.style.SUCCESS("Successfully populated Country model"))
