export const JwtUtil = (configuration) => {
    return `
    package ${configuration.packageName}.utils

    import io.jsonwebtoken.Claims
    import io.jsonwebtoken.Jwts
    import io.jsonwebtoken.SignatureAlgorithm
    import io.jsonwebtoken.security.Keys
    import java.security.Key
    import java.util.*
    
    object JwtUtil {
    
        // Generate a JWT token
        fun generateJwtToken(secretKey: Key, issuer: String, subject: String, expirationMillis: Long): String {
            val currentTimeMillis = System.currentTimeMillis()
            val expirationTimeMillis = currentTimeMillis + expirationMillis
    
            return Jwts.builder()
                .setSubject(subject)
                .setIssuer(issuer)
                .setIssuedAt(Date(currentTimeMillis))
                .setExpiration(Date(expirationTimeMillis))
                .signWith(secretKey, SignatureAlgorithm.HS256)
                .compact()
        }
    
        // Parse and validate a JWT token
        fun parseAndValidateJwtToken(jwtToken: String, secretKey: Key, issuer: String, subject: String): Claims? {
            try {
                return Jwts.parserBuilder()
                    .setSigningKey(secretKey)
                    .requireIssuer(issuer)
                    .requireSubject(subject)
                    .build()
                    .parseClaimsJws(jwtToken)
                    .body
            } catch (e: Exception) {
                // Handle token parsing or validation errors
                return null
            }
        }
    
        // Refresh a JWT token (renew the expiration time)
        fun refreshJwtToken(jwtToken: String, secretKey: Key, expirationMillis: Long): String? {
            val claims = parseAndValidateJwtToken(jwtToken, secretKey, "yourIssuer", "yourSubject")
    
            if (claims != null) {
                val currentTimeMillis = System.currentTimeMillis()
                val expirationTimeMillis = currentTimeMillis + expirationMillis
    
                return Jwts.builder()
                    .setClaims(claims)
                    .setIssuedAt(Date(currentTimeMillis))
                    .setExpiration(Date(expirationTimeMillis))
                    .signWith(secretKey, SignatureAlgorithm.HS256)
                    .compact()
            }
            return null
        }
    }
    
    // Usage example:
    
    /*
        val secretKey = Keys.secretKeyFor(SignatureAlgorithm.HS256) // Generate a secret key
        val issuer = "yourIssuer"
        val subject = "yourSubject"
        val expirationMillis = 3600000 // 1 hour expiration
    
        // Generate a JWT token
        val jwtToken = JwtUtil.generateJwtToken(secretKey, issuer, subject, expirationMillis)
        println("Generated JWT token: $jwtToken")
    
        // Parse and validate a JWT token
        val parsedClaims = JwtUtil.parseAndValidateJwtToken(jwtToken, secretKey, issuer, subject)
        if (parsedClaims != null) {
            println("Parsed and validated JWT token: $parsedClaims")
        } else {
            println("JWT token validation failed.")
        }
    
        // Refresh a JWT token
        val refreshedToken = JwtUtil.refreshJwtToken(jwtToken, secretKey, expirationMillis)
        if (refreshedToken != null) {
            println("Refreshed JWT token: $refreshedToken")
        } else {
            println("JWT token refresh failed.")
        }
    
     */
    
    `
}