import '../enums.dart';

class PermanentStatModifier {
  final String id;
  final String name;
  final String description;
  final StatType statType;
  final ModifierType type;
  final double value;

  const PermanentStatModifier({
    required this.id,
    required this.name,
    required this.description,
    required this.statType,
    required this.type,
    required this.value,
  });

  factory PermanentStatModifier.fromJson(Map<String, dynamic> json) {
    return PermanentStatModifier(
      id: json['id'],
      name: json['name'],
      description: json['description'],
      statType: StatType.values.firstWhere((e) => e.name == json['statType']),
      type: ModifierType.values.firstWhere((e) => e.name == json['type']),
      value: json['value'].toDouble(),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'description': description,
      'statType': statType.name,
      'type': type.name,
      'value': value,
    };
  }
}
