from allauth.socialaccount.models import SocialApp
from django.contrib.sites.models import Site
from django.core.management.base import BaseCommand


class Command(BaseCommand):
    help = "Create social apps for authentication"

    def handle(self, *args, **options):
        # Get the default site
        site = Site.objects.get_or_create(
            id=1,
            defaults={
                "domain": "localhost:8000",
                "name": "ThrillWiki Development",
            },
        )[0]

        # Create Discord app
        discord_app, created = SocialApp.objects.get_or_create(
            provider="discord",
            defaults={
                "name": "Discord",
                "client_id": "1299112802274902047",
                "secret": "ece7Pe_M4mD4mYzAgcINjTEKL_3ftL11",
            },
        )
        if not created:
            discord_app.client_id = "1299112802274902047"
            discord_app.secret = "ece7Pe_M4mD4mYzAgcINjTEKL_3ftL11"
            discord_app.save()
        discord_app.sites.add(site)
        self.stdout.write(f"{'Created' if created else 'Updated'} Discord app")

        # Create Google app
        google_app, created = SocialApp.objects.get_or_create(
            provider="google",
            defaults={
                "name": "Google",
                "client_id": ("135166769591-nopcgmo0fkqfqfs9qe783a137mtmcrt2." "apps.googleusercontent.com"),
                "secret": "GOCSPX-Wd_0Ue0Ue0Ue0Ue0Ue0Ue0Ue0Ue",
            },
        )
        if not created:
            google_app.client_id = "135166769591-nopcgmo0fkqfqfs9qe783a137mtmcrt2." "apps.googleusercontent.com"
            google_app.secret = "GOCSPX-Wd_0Ue0Ue0Ue0Ue0Ue0Ue0Ue0Ue"
            google_app.save()
        google_app.sites.add(site)
        self.stdout.write(f"{'Created' if created else 'Updated'} Google app")
