import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';

class LiveKitTokenGenerator {
  // Your LiveKit Credentials
  static const String apiKey = 'LKMatrixPi';
  static const String apiSecret = 'rYUT2PRaKLedp5VLQCQE83eZG7fjuBWtFPXGiveBmIE';

  static String generate({
    required String roomName,
    required String identity,
    String? displayName,
    int ttlSeconds = 3600, // Valid for 1 hour by default
  }) {
    final jwt = JWT(
      {
        'video': {
          'roomJoin': true,
          'room': roomName,
          'canPublish': true,
          'canSubscribe': true,
          'canPublishData': true,
        },
        'metadata': displayName ?? identity,
      },
      issuer: apiKey,
      subject: identity,
    );

    // Sign the token with your secret
    final token = jwt.sign(
      SecretKey(apiSecret),
      expiresIn: Duration(seconds: ttlSeconds),
    );

    return token;
  }
}
