// SPDX-FileCopyrightText: © 2025 Nøkken.io <nokken.io@proton.me>
// SPDX-License-Identifier: AGPL-3.0
import 'package:nokken/src/features/medication_tracker/models/medication.dart';
import 'package:nokken/src/features/bloodwork_tracker/models/bloodwork.dart';

class GetLabels {
  ///-------------------------------
  /// MEDICATION TYPES
  ///-------------------------------

  /// Get a text description of the medication type and subtype
  static String getMedicationTypeText(Medication medication) {
    switch (medication.medicationType) {
      case MedicationType.oral:
        String subtypeText;
        switch (medication.oralSubtype) {
          case OralSubtype.tablets:
            subtypeText = 'Tablets';
            break;
          case OralSubtype.capsules:
            subtypeText = 'Capsules';
            break;
          case OralSubtype.drops:
            subtypeText = 'Drops';
            break;
          case null:
            subtypeText = 'Oral';
            break;
        }
        return 'Oral${subtypeText.isNotEmpty ? ' - $subtypeText' : ''}';

      case MedicationType.injection:
        return 'Injection';

      case MedicationType.topical:
        String subtypeText;
        switch (medication.topicalSubtype) {
          case TopicalSubtype.gel:
            subtypeText = 'Gel';
            break;
          case TopicalSubtype.cream:
            subtypeText = 'Cream';
            break;
          case TopicalSubtype.spray:
            subtypeText = 'Spray';
            break;
          case null:
            subtypeText = 'Topical';
            break;
        }
        return 'Topical${subtypeText.isNotEmpty ? ' - $subtypeText' : ''}';

      case MedicationType.patch:
        return 'Patch';
    }
  }

  /// Get a text description of the injection subtype
  static String getInjectionSubtypeText(InjectionSubtype injectionSubtype) {
    switch (injectionSubtype) {
      case InjectionSubtype.intravenous:
        return 'Intravenous (IV)';
      case InjectionSubtype.intramuscular:
        return 'Intramuscular (IM)';
      case InjectionSubtype.subcutaneous:
        return 'Subcutaneous (SC)';
    }
  }

// Convert body area enum to user-friendly text
  static String getBodyAreaText(InjectionBodyArea bodyArea) {
    switch (bodyArea) {
      case InjectionBodyArea.abdomen:
        return 'Abdomen';
      case InjectionBodyArea.thigh:
        return 'Thigh';
    }
  }

  /// Format dosage text based on medication type
  static String formatDosageText(Medication medication) {
    switch (medication.medicationType) {
      case MedicationType.oral:
        return medication.dosage;
      case MedicationType.injection:
        String subtypeText = '';
        switch (medication.injectionDetails?.subtype) {
          case InjectionSubtype.intravenous:
            subtypeText = 'IV';
            break;
          case InjectionSubtype.intramuscular:
            subtypeText = 'IM';
            break;
          case InjectionSubtype.subcutaneous:
            subtypeText = 'SC';
            break;
          case null:
            subtypeText = '';
            break;
        }
        return '${medication.dosage}${subtypeText.isNotEmpty ? ' ($subtypeText)' : ''}';
      case MedicationType.topical:
        String subtypeText = '';
        switch (medication.topicalSubtype) {
          case TopicalSubtype.gel:
            subtypeText = 'Gel';
            break;
          case TopicalSubtype.cream:
            subtypeText = 'Cream';
            break;
          case TopicalSubtype.spray:
            subtypeText = 'Spray';
            break;
          case null:
            subtypeText = '';
            break;
        }
        return '${medication.dosage}${subtypeText.isNotEmpty ? ' ($subtypeText)' : ''}';
      case MedicationType.patch:
        return medication.dosage;
    }
  }

  /// Get a short text description for the medication type badge
  static String getTypeBadgeText(Medication medication) {
    switch (medication.medicationType) {
      case MedicationType.oral:
        switch (medication.oralSubtype) {
          case OralSubtype.tablets:
            return 'Tablets';
          case OralSubtype.capsules:
            return 'Capsules';
          case OralSubtype.drops:
            return 'Drops';
          case null:
            return 'Oral';
        }

      case MedicationType.injection:
        switch (medication.injectionDetails?.subtype) {
          case InjectionSubtype.intravenous:
            return 'IV';
          case InjectionSubtype.intramuscular:
            return 'IM';
          case InjectionSubtype.subcutaneous:
            return 'SC';
          case null:
            return 'Injection';
        }

      case MedicationType.topical:
        switch (medication.topicalSubtype) {
          case TopicalSubtype.gel:
            return 'Gel';
          case TopicalSubtype.cream:
            return 'Cream';
          case TopicalSubtype.spray:
            return 'Spray';
          case null:
            return 'Topical';
        }

      case MedicationType.patch:
        return 'Patch';
    }
  }

  /// Get text for completed state based on medication type
  static String getCompletedText(MedicationType medicationType) {
    switch (medicationType) {
      case MedicationType.oral:
        return 'Taken';
      case MedicationType.injection:
        return 'Injected';
      case MedicationType.topical:
        return 'Applied';
      case MedicationType.patch:
        return 'Changed';
    }
  }

  /// Get text for pending state based on medication type
  static String getPendingText(MedicationType medicationType) {
    switch (medicationType) {
      case MedicationType.oral:
        return 'Not taken';
      case MedicationType.injection:
        return 'Not injected';
      case MedicationType.topical:
        return 'Not applied';
      case MedicationType.patch:
        return 'Not changed';
    }
  }

  ///-------------------------------
  /// APPOINTMENT TYPES
  ///-------------------------------
  ///

  /// Get a text description for an appointment type
  static String getAppointmentTypeText(AppointmentType appointmentType) {
    switch (appointmentType) {
      case AppointmentType.bloodwork:
        return 'Bloodwork';
      case AppointmentType.appointment:
        return 'Doctor Visit';
      case AppointmentType.surgery:
        return 'Surgery';
    }
  }
}
