package middleware

import (
	"os"

	ai "github.com/tech/sendico/server/internal/api/config"
)

type (
	TokenConfig    = ai.TokenConfig
	Config         = ai.Config
	Signature      = ai.SignatureConf
	PasswordConfig = ai.PasswordConfig
)

type MapClaims = ai.MapClaims

func getKey(osEnv string) any {
	if len(osEnv) == 0 {
		return nil
	}
	return []byte(os.Getenv(osEnv))
}

func SignatureConf(conf *Config) Signature {
	return Signature{
		PrivateKey: []byte(os.Getenv(conf.Signature.PrivateKeyEnv)),
		PublicKey:  getKey(conf.Signature.PublicKeyEnv),
		Algorithm:  conf.Signature.Algorithm,
	}
}
