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

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.id}, 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.id}, 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.id}, 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.id}, Domain: {site.domain}, Name: {site.name}')
