import 'package:fis_common/event/event_type.dart';
import 'package:fis_measure/interfaces/enums/items.dart';

import '../calculators/calculator.dart';
import '../workspace/point_info.dart';
import 'item_feature.dart';

class ItemMeta {
  String name;
  Map<String, dynamic> args;
  List<ItemMeta> childItems;

  ItemMeta(
    this.name,
    this.args, {
    this.childItems = const [],
  });

  T? getItem<T>(String key) {
    if (!args.containsKey(key)) return null;
    final value = args[key]! as T;
    return value;
  }
}

abstract class IMeasureItem {
  /// 标签信息
  ItemMeta get meta;

  /// 描述
  String get description;

  /// 简短描述
  String get briefAnnotation;

  /// 计算公式
  String get workingFormular;

  /// 测量快照
  IMeasureItemFeature? get feature;

  /// 已完成测量记录
  List<IMeasureItemFeature> get measuredFeatures;

  /// 计算器
  ICalculator? get calculator;

  /// 父级
  IMeasureItem? get parent;

  /// 测量状态
  ItemStates get state;

  /// 处理输入
  bool execute(PointInfo args);

  /// 快照变化事件
  late FEventHandler<IMeasureItemFeature?> featureUpdated;
}
