import 'package:fis_jsonrpc/rpc.dart';
import 'package:vnoteapp/rpc.dart';
import 'package:vnoteapp/store/store.dart';

import 'interfaces/label.dart';
import 'package:fis_common/logger/logger.dart';

class LabelManager implements ILabelManager {
  @override
  Future<List<LabelDTO>?> getLabelListByKey(String key) async {
    try {
      final result = await rpc.label.getLabelListByKeyAsync(
        GetLabelListByKeyRequest(key: key, token: Store.user.token),
      );
      return result;
    } catch (e) {
      logger.e("LabelManager get labels by key-$key error.", e);
      return null;
    }
  }

  @override
  Future<List<LabelDTO>> getNormalCrowdLabels() async {
    return (await getLabelListByKey("RQFL")) ?? [];
  }

  @override
  Future<List<LabelDTO>> getDiseaseCrowdLabels() async {
    return (await getLabelListByKey("CJJB")) ?? [];
  }

  @override
  Future<List<LabelDTO>> getSpecialCareCrowdLabels() async {
    return (await getLabelListByKey("TSZG")) ?? [];
  }
}
