
import os
import django
from django.conf import settings
from django_tenants.utils import tenant_context
from smoothschedule.identity.core.models import Tenant

# Setup Django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")
django.setup()

from django.urls import resolve, reverse

print(f"ROOT_URLCONF: {settings.ROOT_URLCONF}")

try:
    tenant = Tenant.objects.get(schema_name='demo')
    print(f"Found tenant: {tenant}")
    
    with tenant_context(tenant):
        print(f"Active schema: {tenant.schema_name}")
        try:
            match = resolve('/api/resources/')
            print(f"Resolved /api/resources/: {match}")
        except Exception as e:
            print(f"Failed to resolve /api/resources/: {e}")
            
        try:
            match = resolve('/api/schedule/resources/')
            print(f"Resolved /api/schedule/resources/: {match}")
        except Exception as e:
            print(f"Failed to resolve /api/schedule/resources/: {e}")

except Tenant.DoesNotExist:
    print("Demo tenant not found")
