package org.xyzh.common.auth.token;

import io.jsonwebtoken.Claims;
import org.springframework.stereotype.Component;
import org.xyzh.common.auth.utils.JwtTokenUtil;

/**
 * @description    JwtTokenParser.java文件描述 JWT令牌解析器实现类
 * @filename    JwtTokenParser.java
 * @author    yslg
 * @copyright yslg
 * @since 2025-11-07
 */
@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);
    }
}

