package org.xyzh.auth.security;

import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.xyzh.auth.util.JwtTokenUtil;
import org.xyzh.common.core.security.TokenParser;

/**
 * @description    JwtTokenParser.java文件描述 JWT令牌解析器实现类
 * @filename    JwtTokenParser.java
 * @author    yslg
 * @copyright xyzh
 * @since 2025-10-06
 */
@Component
public class JwtTokenParser implements TokenParser {
    
    private final JwtTokenUtil jwtTokenUtil;
    
    /**
     * Spring会自动注入，无需@Autowired注解
     */
    public JwtTokenParser(JwtTokenUtil jwtTokenUtil) {
        this.jwtTokenUtil = jwtTokenUtil;
    }
    
    @Override
    public String getUserIdFromToken(String token) {
        return jwtTokenUtil.getUserIdFromToken(token);
    }
    
    @Override
    public Claims getAllClaimsFromToken(String token) {
        return jwtTokenUtil.getAllClaimsFromToken(token);
    }
    
    @Override
    public boolean validateToken(String token, String userId) {
        return jwtTokenUtil.validateToken(token, userId);
    }
    
    @Override
    public boolean isTokenExpired(String token) {
        return jwtTokenUtil.isTokenExpired(token);
    }
}

