<?php

namespace App\Libraries;

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

class JwtService
{
    private $key;

    public function __construct()
    {
        $this->key = getenv('JWT_SECRET') ?: 'SECRET_LAUNDRY';
    }

    public function generate($data)
    {
        $payload = [
            'iss' => 'laundry-app',
            'iat' => time(),
            'exp' => time() + 86400, // 1 hari
            'data' => $data
        ];

        return JWT::encode($payload, $this->key, 'HS256');
    }

    public function decode($token)
    {
        return JWT::decode($token, new Key($this->key, 'HS256'));
    }
}