package com.ai.da.common.utils;

import com.ai.da.model.vo.AuthPrincipalVo;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class SecurityContextUtils {

    public static AuthPrincipalVo getCurrentUser() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication != null && authentication.getPrincipal() != null) {
            return (AuthPrincipalVo) authentication.getPrincipal();
        }
        return null;
    }

    public static Long getCurrentUserId() {
        AuthPrincipalVo currentUser = getCurrentUser();
        if (currentUser != null) {
            return currentUser.getId();
        }
        return null;
    }

    public static String getCurrentUsername() {
        AuthPrincipalVo currentUser = getCurrentUser();
        if (currentUser != null) {
            return currentUser.getUsername();
        }
        return null;
    }
}
