from rest_framework_simplejwt.authentication import JWTAuthentication
from .models import AdminTable
from rest_framework.exceptions import AuthenticationFailed

class AdminJWTAuthentication(JWTAuthentication):
    def get_user(self, validated_token):
        admin_id = validated_token.get("user_id")

        if admin_id is None:
            raise AuthenticationFailed("User ID not found in token")

        try:
            admin = AdminTable.objects.get(id=admin_id)
        except AdminTable.DoesNotExist:
            raise AuthenticationFailed("No such admin found")

        return admin