/**
 * Token Service
 * Handles JWT token generation and verification
 */
import jwt from "jsonwebtoken";
export function createTokenService(config) {
    const expiresIn = config.expiresIn ?? "7d";
    return {
        generateToken(payload) {
            return jwt.sign(payload, config.secret, { expiresIn });
        },
        verifyToken(token) {
            try {
                const decoded = jwt.verify(token, config.secret);
                return decoded;
            }
            catch (error) {
                return null;
            }
        },
        decodeToken(token) {
            try {
                const decoded = jwt.decode(token);
                return decoded;
            }
            catch (error) {
                return null;
            }
        },
        generateUserToken({ user, role, session, tenant }) {
            const payload = {
                id: user.id,
                role_Id: role.id,
                sessionToken: session.token,
            };
            if (tenant) {
                payload.tenant_Id = tenant.id;
            }
            return this.generateToken(payload);
        },
    };
}
export default createTokenService;
//# sourceMappingURL=token.js.map