import {
  generateAccessToken as coreGenerateAccessToken,
  generateRefreshToken as coreGenerateRefreshToken,
  verifyToken as coreVerifyToken,
  decodeToken,
  type TokenConfig,
} from '@horux/core';
import type { JWTPayload } from '@horux/shared';
import { env } from '../config/env.js';

const tokenConfig: TokenConfig = {
  secret: env.JWT_SECRET,
  accessExpiresIn: env.JWT_EXPIRES_IN,
  refreshExpiresIn: env.JWT_REFRESH_EXPIRES_IN,
};

export function generateAccessToken(payload: Omit<JWTPayload, 'iat' | 'exp'>): string {
  return coreGenerateAccessToken(payload, tokenConfig);
}

export function generateRefreshToken(payload: Omit<JWTPayload, 'iat' | 'exp'>): string {
  return coreGenerateRefreshToken(payload, tokenConfig);
}

export function verifyToken(token: string): JWTPayload {
  return coreVerifyToken(token, tokenConfig.secret);
}

export { decodeToken };
export type { JWTPayload };
