// SPDX-FileCopyrightText: 2026 FocusFlow contributors
// SPDX-License-Identifier: AGPL-3.0-only

part of '../../document_mapping.dart';

/// Stable enum encode/decode helpers for V1 document maps.
abstract final class PersistenceEnumMapping {
  /// Performs the `encodeNullable` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static String? encodeNullable(Enum? value) {
    return value == null ? null : encode(value);
  }

  /// Performs the `encode` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static String encode(Enum value) {
    if (value is TaskType) return encodeTaskType(value);
    if (value is TaskStatus) return encodeTaskStatus(value);
    if (value is PriorityLevel) return encodePriority(value);
    if (value is RewardLevel) return encodeReward(value);
    if (value is DifficultyLevel) return encodeDifficulty(value);
    if (value is ReminderProfile) return encodeReminderProfile(value);
    if (value is BacklogTag) return encodeBacklogTag(value);
    if (value is LockedWeekday) return encodeLockedWeekday(value);
    if (value is LockedBlockOverrideType) {
      return encodeLockedBlockOverrideType(value);
    }
    if (value is TaskActivityCode) return encodeTaskActivityCode(value);
    if (value is SchedulingNoticeType) return encodeSchedulingNoticeType(value);
    if (value is SchedulingIssueCode) return encodeSchedulingIssueCode(value);
    if (value is SchedulingMovementCode) {
      return encodeSchedulingMovementCode(value);
    }
    if (value is SchedulingConflictCode) {
      return encodeSchedulingConflictCode(value);
    }
    if (value is ProjectCompletionTimeBucket) {
      return encodeProjectCompletionTimeBucket(value);
    }
    throw DocumentMappingException(
      code: DocumentMappingFailureCode.unknownCode,
      detailCode: value.runtimeType.toString(),
    );
  }

  /// Performs the `encodeTaskType` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static String encodeTaskType(TaskType value) => switch (value) {
        TaskType.flexible => 'flexible',
        TaskType.inflexible => 'inflexible',
        TaskType.critical => 'critical',
        TaskType.locked => 'locked',
        TaskType.surprise => 'surprise',
        TaskType.freeSlot => 'free_slot',
      };

  /// Performs the `decodeTaskType` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static TaskType decodeTaskType(String value) {
    return _decodeCode(_taskTypeByCode, value, 'TaskType');
  }

  /// Performs the `encodeTaskStatus` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static String encodeTaskStatus(TaskStatus value) => switch (value) {
        TaskStatus.planned => 'planned',
        TaskStatus.active => 'active',
        TaskStatus.completed => 'completed',
        TaskStatus.missed => 'missed',
        TaskStatus.cancelled => 'cancelled',
        TaskStatus.noLongerRelevant => 'no_longer_relevant',
        TaskStatus.backlog => 'backlog',
      };

  /// Performs the `decodeTaskStatus` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static TaskStatus decodeTaskStatus(String value) {
    return _decodeCode(_taskStatusByCode, value, 'TaskStatus');
  }

  /// Performs the `encodePriority` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static String encodePriority(PriorityLevel value) => switch (value) {
        PriorityLevel.veryLow => 'very_low',
        PriorityLevel.low => 'low',
        PriorityLevel.medium => 'medium',
        PriorityLevel.high => 'high',
        PriorityLevel.veryHigh => 'very_high',
      };

  /// Performs the `decodeNullablePriority` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static PriorityLevel? decodeNullablePriority(String? value) {
    return value == null
        ? null
        : _decodeCode(_priorityByCode, value, 'PriorityLevel');
  }

  /// Performs the `encodeReward` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static String encodeReward(RewardLevel value) => switch (value) {
        RewardLevel.notSet => 'not_set',
        RewardLevel.veryLow => 'very_low',
        RewardLevel.low => 'low',
        RewardLevel.medium => 'medium',
        RewardLevel.high => 'high',
        RewardLevel.veryHigh => 'very_high',
      };

  /// Performs the `decodeReward` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static RewardLevel decodeReward(String value) {
    return _decodeCode(_rewardByCode, value, 'RewardLevel');
  }

  /// Performs the `encodeDifficulty` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static String encodeDifficulty(DifficultyLevel value) => switch (value) {
        DifficultyLevel.notSet => 'not_set',
        DifficultyLevel.veryEasy => 'very_easy',
        DifficultyLevel.easy => 'easy',
        DifficultyLevel.medium => 'medium',
        DifficultyLevel.hard => 'hard',
        DifficultyLevel.veryHard => 'very_hard',
      };

  /// Performs the `decodeDifficulty` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static DifficultyLevel decodeDifficulty(String value) {
    return _decodeCode(_difficultyByCode, value, 'DifficultyLevel');
  }

  /// Performs the `encodeReminderProfile` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static String encodeReminderProfile(ReminderProfile value) => switch (value) {
        ReminderProfile.silent => 'silent',
        ReminderProfile.gentle => 'gentle',
        ReminderProfile.persistent => 'persistent',
        ReminderProfile.strict => 'strict',
      };

  /// Performs the `decodeNullableReminderProfile` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static ReminderProfile? decodeNullableReminderProfile(String? value) {
    return value == null
        ? null
        : _decodeCode(_reminderProfileByCode, value, 'ReminderProfile');
  }

  /// Performs the `encodeBacklogTag` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static String encodeBacklogTag(BacklogTag value) => switch (value) {
        BacklogTag.wishlist => 'wishlist',
      };

  /// Performs the `decodeBacklogTag` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static BacklogTag decodeBacklogTag(String value) {
    return _decodeCode(_backlogTagByCode, value, 'BacklogTag');
  }

  /// Performs the `encodeLockedWeekday` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static String encodeLockedWeekday(LockedWeekday value) => switch (value) {
        LockedWeekday.monday => 'monday',
        LockedWeekday.tuesday => 'tuesday',
        LockedWeekday.wednesday => 'wednesday',
        LockedWeekday.thursday => 'thursday',
        LockedWeekday.friday => 'friday',
        LockedWeekday.saturday => 'saturday',
        LockedWeekday.sunday => 'sunday',
      };

  /// Performs the `decodeLockedWeekday` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static LockedWeekday decodeLockedWeekday(String value) {
    return _decodeCode(_lockedWeekdayByCode, value, 'LockedWeekday');
  }

  /// Performs the `encodeLockedBlockOverrideType` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static String encodeLockedBlockOverrideType(
    LockedBlockOverrideType value,
  ) =>
      switch (value) {
        LockedBlockOverrideType.remove => 'remove',
        LockedBlockOverrideType.replace => 'replace',
        LockedBlockOverrideType.add => 'add',
      };

  /// Performs the `decodeLockedBlockOverrideType` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static LockedBlockOverrideType decodeLockedBlockOverrideType(String value) {
    return _decodeCode(
      _lockedBlockOverrideTypeByCode,
      value,
      'LockedBlockOverrideType',
    );
  }

  /// Performs the `encodeTaskActivityCode` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static String encodeTaskActivityCode(TaskActivityCode value) =>
      switch (value) {
        TaskActivityCode.completed => 'completed',
        TaskActivityCode.missed => 'missed',
        TaskActivityCode.cancelled => 'cancelled',
        TaskActivityCode.noLongerRelevant => 'no_longer_relevant',
        TaskActivityCode.manuallyPushed => 'manually_pushed',
        TaskActivityCode.automaticallyPushed => 'automatically_pushed',
        TaskActivityCode.movedToBacklog => 'moved_to_backlog',
        TaskActivityCode.restoredFromBacklog => 'restored_from_backlog',
        TaskActivityCode.activated => 'activated',
      };

  /// Performs the `decodeTaskActivityCode` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static TaskActivityCode decodeTaskActivityCode(String value) {
    return _decodeCode(_taskActivityCodeByCode, value, 'TaskActivityCode');
  }

  /// Performs the `encodeSchedulingNoticeType` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static String encodeSchedulingNoticeType(SchedulingNoticeType value) =>
      switch (value) {
        SchedulingNoticeType.info => 'info',
        SchedulingNoticeType.moved => 'moved',
        SchedulingNoticeType.overlap => 'overlap',
        SchedulingNoticeType.noFit => 'no_fit',
        SchedulingNoticeType.overflow => 'overflow',
      };

  /// Performs the `decodeSchedulingNoticeType` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static SchedulingNoticeType decodeSchedulingNoticeType(String value) {
    return _decodeCode(
      _schedulingNoticeTypeByCode,
      value,
      'SchedulingNoticeType',
    );
  }

  /// Performs the `encodeSchedulingIssueCode` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static String encodeSchedulingIssueCode(SchedulingIssueCode value) =>
      switch (value) {
        SchedulingIssueCode.taskNotFound => 'task_not_found',
        SchedulingIssueCode.invalidTaskState => 'invalid_task_state',
        SchedulingIssueCode.missingDuration => 'missing_duration',
        SchedulingIssueCode.missingScheduledSlot => 'missing_scheduled_slot',
        SchedulingIssueCode.nonPositiveDuration => 'non_positive_duration',
        SchedulingIssueCode.noAvailableSlot => 'no_available_slot',
        SchedulingIssueCode.unfinishedTasksCouldNotFit =>
          'unfinished_tasks_could_not_fit',
        SchedulingIssueCode.noUnfinishedFlexibleTasks =>
          'no_unfinished_flexible_tasks',
        SchedulingIssueCode.duplicateSurpriseLog => 'duplicate_surprise_log',
      };

  /// Performs the `decodeNullableSchedulingIssueCode` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static SchedulingIssueCode? decodeNullableSchedulingIssueCode(String? value) {
    return value == null
        ? null
        : _decodeCode(
            _schedulingIssueCodeByCode,
            value,
            'SchedulingIssueCode',
          );
  }

  /// Performs the `encodeSchedulingMovementCode` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static String encodeSchedulingMovementCode(SchedulingMovementCode value) =>
      switch (value) {
        SchedulingMovementCode.backlogTaskInserted => 'backlog_task_inserted',
        SchedulingMovementCode.flexibleTaskMovedToMakeRoom =>
          'flexible_task_moved_to_make_room',
        SchedulingMovementCode.flexibleTaskPushedToNextAvailableSlot =>
          'flexible_task_pushed_to_next_available_slot',
        SchedulingMovementCode.flexibleTaskMovedToTomorrow =>
          'flexible_task_moved_to_tomorrow',
        SchedulingMovementCode.unfinishedFlexibleTasksRolledOver =>
          'unfinished_flexible_tasks_rolled_over',
        SchedulingMovementCode.flexibleTaskMovedToBacklog =>
          'flexible_task_moved_to_backlog',
        SchedulingMovementCode.requiredCommitmentScheduled =>
          'required_commitment_scheduled',
      };

  /// Performs the `decodeNullableSchedulingMovementCode` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static SchedulingMovementCode? decodeNullableSchedulingMovementCode(
    String? value,
  ) {
    return value == null
        ? null
        : _decodeCode(
            _schedulingMovementCodeByCode,
            value,
            'SchedulingMovementCode',
          );
  }

  /// Performs the `encodeSchedulingConflictCode` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static String encodeSchedulingConflictCode(SchedulingConflictCode value) =>
      switch (value) {
        SchedulingConflictCode.flexibleTaskOverlapsBlockedTime =>
          'flexible_task_overlaps_blocked_time',
        SchedulingConflictCode.surpriseTaskOverlapsRequiredVisibleTime =>
          'surprise_task_overlaps_required_visible_time',
        SchedulingConflictCode.requiredCommitmentOverlapsProtectedFreeSlot =>
          'required_commitment_overlaps_protected_free_slot',
      };

  /// Performs the `decodeNullableSchedulingConflictCode` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static SchedulingConflictCode? decodeNullableSchedulingConflictCode(
    String? value,
  ) {
    return value == null
        ? null
        : _decodeCode(
            _schedulingConflictCodeByCode,
            value,
            'SchedulingConflictCode',
          );
  }

  /// Performs the `encodeProjectCompletionTimeBucket` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static String encodeProjectCompletionTimeBucket(
    ProjectCompletionTimeBucket value,
  ) =>
      switch (value) {
        ProjectCompletionTimeBucket.overnight => 'overnight',
        ProjectCompletionTimeBucket.morning => 'morning',
        ProjectCompletionTimeBucket.afternoon => 'afternoon',
        ProjectCompletionTimeBucket.evening => 'evening',
        ProjectCompletionTimeBucket.night => 'night',
      };

  /// Performs the `decodeProjectCompletionTimeBucket` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  static ProjectCompletionTimeBucket decodeProjectCompletionTimeBucket(
    String value,
  ) {
    return _decodeCode(
      _projectCompletionTimeBucketByCode,
      value,
      'ProjectCompletionTimeBucket',
    );
  }
}
