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


class Command(BaseCommand):
    help = "Check all social auth related tables"

    def handle(self, *args, **options):
        # Check SocialApp
        self.stdout.write("\nChecking SocialApp table:")
        for app in SocialApp.objects.all():
            self.stdout.write(
                f"ID: {app.pk}, Provider: {app.provider}, Name: {app.name}, Client ID: {
                    app.client_id
                }"
            )
            self.stdout.write("Sites:")
            for site in app.sites.all():
                self.stdout.write(f"  - {site.domain}")

        # Check SocialAccount
        self.stdout.write("\nChecking SocialAccount table:")
        for account in SocialAccount.objects.all():
            self.stdout.write(f"ID: {account.pk}, Provider: {account.provider}, UID: {account.uid}")

        # Check SocialToken
        self.stdout.write("\nChecking SocialToken table:")
        for token in SocialToken.objects.all():
            self.stdout.write(f"ID: {token.pk}, Account: {token.account}, App: {token.app}")

        # Check Site
        self.stdout.write("\nChecking Site table:")
        for site in Site.objects.all():
            self.stdout.write(f"ID: {site.pk}, Domain: {site.domain}, Name: {site.name}")
