import 'package:hub/features/module/index.dart';

enum ModuleStatus { active, inactive, disabled }

enum EnumDisplay {
  active('VISIVEL'),
  inactive('INVISIVEL'),
  expired('DESABILITADO');

  final String value;
  const EnumDisplay(this.value);

  static EnumDisplay fromString(String? value) {
    if (value == null) return EnumDisplay.inactive;
    switch (value) {
      case 'VISIVEL':
        return EnumDisplay.active;
      case 'INVISIVEL':
        return EnumDisplay.inactive;
      case 'DESABILITADO':
        return EnumDisplay.expired;
      default:
        return EnumDisplay.inactive;
    }
  }
}

extension ModuleStatusExtension on ModuleStatus {
  String get key {
    switch (this) {
      case ModuleStatus.active:
        return 'VISIVEL';
      case ModuleStatus.inactive:
        return 'INVISIVEL';
      case ModuleStatus.disabled:
        return 'DESABILITADO';
    }
  }
}

class Module {
  final String key;
  final String display;
  final String expirationDate;
  final String startDate;
  final int quantity;

  Module({
    required this.key,
    required this.display,
    required this.expirationDate,
    required this.startDate,
    required this.quantity,
  });

  factory Module.fromModel(ModuleModel model) {
    return Module(
      key: model.key,
      display: model.display,
      expirationDate: model.expirationDate,
      startDate: model.startDate,
      quantity: model.quantity,
    );
  }

  ModuleModel toModel() {
    return ModuleModel(
      key: key,
      display: display,
      expirationDate: expirationDate,
      startDate: startDate,
      quantity: quantity,
    );
  }
}
