import 'package:flyinsono/architecture/states/states.dart';
import 'package:flyinsono/managers/base_manager.dart';
import 'package:flyinsono/managers/interfaces/product_key.dart';
import 'package:flyinsono/rpc.dart';
import 'package:fis_jsonrpc/services/researchEdition.m.dart';

class ProductKeyManager extends BaseManager implements IProductKeyManager {
  @override
  Future<int> activationLicenseAsync(String licenseCode) async {
    try {
      var request = ActivationLicenseRequest(
        token: Store.user.token,
        licenseCode: licenseCode,
      );
      var result = await rpc.researchEdition.activationLicenseAsync(request);
      return result;
    } catch (e) {
      return 0;
    }
  }

  @override
  Future<LicenseInfoDTO?> getLicenseInfoAsync() async {
    try {
      var result = await rpc.researchEdition
          .getLicenseInfoAsync(TokenRequest(token: Store.user.token));
      return result;
    } catch (e) {
      return null;
    }
  }
}
