<?php

require_once __DIR__ . '/../vendor/autoload.php'; // <-- esto carga la librería de JWT

use Firebase\JWT\JWT;
use Firebase\JWT\Key;

require_once 'config/config.php';

class Auth {
    public static function generateToken($userId, $clientId) {
        $issuedAt = time();
        $payload = [
            "iss" => JWT_ISSUER,
            "iat" => $issuedAt,
            "exp" => $issuedAt + JWT_EXPIRE,
            "uid" => $userId,
            "cid" => $clientId
        ];
        return JWT::encode($payload, JWT_SECRET, 'HS256');
    }

    public static function validateToken($token) {
        return JWT::decode($token, new Key(JWT_SECRET, 'HS256'));
    }
}
