package com.service.impl;

import com.alibaba.fastjson.JSON;
import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.Claim;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.service.JwtService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Service
public class JwtServiceImpl implements JwtService {
    private static final String TOKEN_SECRET = "ZXY";
    @Override
    public String generateToken(String userId) {
        Algorithm algorithm = Algorithm.HMAC256(TOKEN_SECRET);
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("type","jwt");
        return JWT.create()
                .withIssuedAt(new Date())
                .withClaim("token","userToken")
                .sign(algorithm);
    }

    @Override
    public void parseToken(String token) {
        Algorithm algorithm = Algorithm.HMAC256(TOKEN_SECRET);
        JWTVerifier build = JWT.require(algorithm).build();
        DecodedJWT verify = build.verify(token);
        String pa = verify.getClaim("token").asString();
//        Map hashMap = JSON.parseObject(pa, Map.class);
    }
}
