use crate::app::context_clues::{
  BLOCKLIST_CONTEXT_CLUES, DOWNLOADS_CONTEXT_CLUES, HISTORY_CONTEXT_CLUES, INDEXERS_CONTEXT_CLUES,
  ROOT_FOLDERS_CONTEXT_CLUES, SYSTEM_CONTEXT_CLUES,
};
use crate::app::radarr::radarr_context_clues::{
  COLLECTIONS_CONTEXT_CLUES, LIBRARY_CONTEXT_CLUES, MANUAL_MOVIE_SEARCH_CONTEXT_CLUES,
  MOVIE_DETAILS_CONTEXT_CLUES,
};
use crate::models::radarr_models::{
  AddMovieSearchResult, BlocklistItem, Collection, CollectionMovie, DownloadRecord,
  IndexerSettings, Movie, RadarrHistoryItem, RadarrTask,
};
use crate::models::servarr_data::modals::{EditIndexerModal, IndexerTestResultModalItem};
use crate::models::servarr_data::radarr::modals::{
  AddMovieModal, EditCollectionModal, EditMovieModal, MovieDetailsModal,
};
use crate::models::servarr_models::{DiskSpace, Indexer, QueueEvent, RootFolder};
use crate::models::stateful_list::StatefulList;
use crate::models::stateful_table::StatefulTable;
use crate::models::{
  BlockSelectionState, HorizontallyScrollableText, Route, ScrollableText, TabRoute, TabState,
};
use crate::network::radarr_network::RadarrEvent;
use bimap::BiMap;
use chrono::{DateTime, Utc};
use itertools::Itertools;
use serde_json::Number;
use strum::EnumIter;
#[cfg(test)]
use {
  crate::models::radarr_models::{MinimumAvailability, MovieMonitor},
  crate::models::stateful_table::SortOption,
  crate::network::radarr_network::radarr_network_test_utils::test_utils::root_folder,
  crate::network::radarr_network::radarr_network_test_utils::test_utils::{
    add_movie_search_result, blocklist_item, cast_credit, collection, collection_movie,
    crew_credit, download_record, indexer, log_line, movie, movie_history_item,
    quality_profile_map, radarr_history_item, tags_map, task, torrent_release, updates,
    usenet_release,
  },
  crate::network::servarr_test_utils::diskspace,
  crate::network::servarr_test_utils::indexer_test_result,
  crate::network::servarr_test_utils::queued_event,
  crate::sort_option,
  strum::IntoEnumIterator,
  strum_macros::{Display, EnumString},
};

#[cfg(test)]
#[path = "radarr_data_tests.rs"]
mod radarr_data_tests;

#[cfg(test)]
#[path = "radarr_test_utils.rs"]
pub mod radarr_test_utils;

pub struct RadarrData<'a> {
  pub root_folders: StatefulTable<RootFolder>,
  pub disk_space_vec: Vec<DiskSpace>,
  pub version: String,
  pub start_time: DateTime<Utc>,
  pub movies: StatefulTable<Movie>,
  pub selected_block: BlockSelectionState<'a, ActiveRadarrBlock>,
  pub downloads: StatefulTable<DownloadRecord>,
  pub indexers: StatefulTable<Indexer>,
  pub blocklist: StatefulTable<BlocklistItem>,
  pub history: StatefulTable<RadarrHistoryItem>,
  pub quality_profile_map: BiMap<i64, String>,
  pub tags_map: BiMap<i64, String>,
  pub collections: StatefulTable<Collection>,
  pub collection_movies: StatefulTable<CollectionMovie>,
  pub logs: StatefulList<HorizontallyScrollableText>,
  pub log_details: StatefulList<HorizontallyScrollableText>,
  pub tasks: StatefulTable<RadarrTask>,
  pub queued_events: StatefulTable<QueueEvent>,
  pub updates: ScrollableText,
  pub main_tabs: TabState,
  pub movie_info_tabs: TabState,
  pub add_movie_search: Option<HorizontallyScrollableText>,
  pub add_movie_modal: Option<AddMovieModal>,
  pub add_searched_movies: Option<StatefulTable<AddMovieSearchResult>>,
  pub edit_movie_modal: Option<EditMovieModal>,
  pub edit_collection_modal: Option<EditCollectionModal>,
  pub edit_indexer_modal: Option<EditIndexerModal>,
  pub edit_root_folder: Option<HorizontallyScrollableText>,
  pub indexer_settings: Option<IndexerSettings>,
  pub indexer_test_errors: Option<String>,
  pub indexer_test_all_results: Option<StatefulTable<IndexerTestResultModalItem>>,
  pub movie_details_modal: Option<MovieDetailsModal>,
  pub prompt_confirm: bool,
  pub prompt_confirm_action: Option<RadarrEvent>,
  pub delete_movie_files: bool,
  pub add_list_exclusion: bool,
}

impl RadarrData<'_> {
  pub fn reset_delete_movie_preferences(&mut self) {
    self.delete_movie_files = false;
    self.add_list_exclusion = false;
  }

  pub fn reset_movie_info_tabs(&mut self) {
    self.movie_details_modal = None;
    self.movie_info_tabs.index = 0;
  }

  pub fn tag_ids_to_display(&self, tag_ids: &[Number]) -> String {
    tag_ids
      .iter()
      .filter_map(|tag_id| {
        let id = tag_id.as_i64()?;
        self.tags_map.get_by_left(&id).cloned()
      })
      .collect::<Vec<_>>()
      .join(", ")
  }

  pub fn sorted_quality_profile_names(&self) -> Vec<String> {
    self
      .quality_profile_map
      .iter()
      .sorted_by_key(|(id, _)| *id)
      .map(|(_, name)| name)
      .cloned()
      .collect()
  }
}

impl<'a> Default for RadarrData<'a> {
  fn default() -> RadarrData<'a> {
    RadarrData {
      root_folders: StatefulTable::default(),
      disk_space_vec: Vec::new(),
      version: String::new(),
      start_time: DateTime::default(),
      movies: StatefulTable::default(),
      selected_block: BlockSelectionState::default(),
      downloads: StatefulTable::default(),
      indexers: StatefulTable::default(),
      blocklist: StatefulTable::default(),
      history: StatefulTable::default(),
      quality_profile_map: BiMap::default(),
      tags_map: BiMap::default(),
      collections: StatefulTable::default(),
      collection_movies: StatefulTable::default(),
      logs: StatefulList::default(),
      log_details: StatefulList::default(),
      tasks: StatefulTable::default(),
      queued_events: StatefulTable::default(),
      updates: ScrollableText::default(),
      add_movie_search: None,
      add_movie_modal: None,
      add_searched_movies: None,
      edit_movie_modal: None,
      edit_collection_modal: None,
      edit_indexer_modal: None,
      edit_root_folder: None,
      indexer_settings: None,
      indexer_test_errors: None,
      indexer_test_all_results: None,
      movie_details_modal: None,
      prompt_confirm: false,
      prompt_confirm_action: None,
      delete_movie_files: false,
      add_list_exclusion: false,
      main_tabs: TabState::new(vec![
        TabRoute {
          title: "Library".to_string(),
          route: ActiveRadarrBlock::Movies.into(),
          contextual_help: Some(&LIBRARY_CONTEXT_CLUES),
          config: None,
        },
        TabRoute {
          title: "Collections".to_string(),
          route: ActiveRadarrBlock::Collections.into(),
          contextual_help: Some(&COLLECTIONS_CONTEXT_CLUES),
          config: None,
        },
        TabRoute {
          title: "Downloads".to_string(),
          route: ActiveRadarrBlock::Downloads.into(),
          contextual_help: Some(&DOWNLOADS_CONTEXT_CLUES),
          config: None,
        },
        TabRoute {
          title: "Blocklist".to_string(),
          route: ActiveRadarrBlock::Blocklist.into(),
          contextual_help: Some(&BLOCKLIST_CONTEXT_CLUES),
          config: None,
        },
        TabRoute {
          title: "History".to_string(),
          route: ActiveRadarrBlock::History.into(),
          contextual_help: Some(&HISTORY_CONTEXT_CLUES),
          config: None,
        },
        TabRoute {
          title: "Root Folders".to_string(),
          route: ActiveRadarrBlock::RootFolders.into(),
          contextual_help: Some(&ROOT_FOLDERS_CONTEXT_CLUES),
          config: None,
        },
        TabRoute {
          title: "Indexers".to_string(),
          route: ActiveRadarrBlock::Indexers.into(),
          contextual_help: Some(&INDEXERS_CONTEXT_CLUES),
          config: None,
        },
        TabRoute {
          title: "System".to_string(),
          route: ActiveRadarrBlock::System.into(),
          contextual_help: Some(&SYSTEM_CONTEXT_CLUES),
          config: None,
        },
      ]),
      movie_info_tabs: TabState::new(vec![
        TabRoute {
          title: "Details".to_string(),
          route: ActiveRadarrBlock::MovieDetails.into(),
          contextual_help: Some(&MOVIE_DETAILS_CONTEXT_CLUES),
          config: None,
        },
        TabRoute {
          title: "History".to_string(),
          route: ActiveRadarrBlock::MovieHistory.into(),
          contextual_help: Some(&MOVIE_DETAILS_CONTEXT_CLUES),
          config: None,
        },
        TabRoute {
          title: "File".to_string(),
          route: ActiveRadarrBlock::FileInfo.into(),
          contextual_help: Some(&MOVIE_DETAILS_CONTEXT_CLUES),
          config: None,
        },
        TabRoute {
          title: "Cast".to_string(),
          route: ActiveRadarrBlock::Cast.into(),
          contextual_help: Some(&MOVIE_DETAILS_CONTEXT_CLUES),
          config: None,
        },
        TabRoute {
          title: "Crew".to_string(),
          route: ActiveRadarrBlock::Crew.into(),
          contextual_help: Some(&MOVIE_DETAILS_CONTEXT_CLUES),
          config: None,
        },
        TabRoute {
          title: "Manual Search".to_string(),
          route: ActiveRadarrBlock::ManualSearch.into(),
          contextual_help: Some(&MANUAL_MOVIE_SEARCH_CONTEXT_CLUES),
          config: None,
        },
      ]),
    }
  }
}

#[cfg(test)]
impl RadarrData<'_> {
  pub fn test_default_fully_populated() -> Self {
    let quality_profile_name = "HD - 1080p".to_owned();
    let mut add_movie_modal = AddMovieModal {
      tags: "alex".into(),
      ..AddMovieModal::default()
    };
    add_movie_modal
      .root_folder_list
      .set_items(vec![root_folder()]);
    add_movie_modal
      .monitor_list
      .set_items(MovieMonitor::iter().collect());
    add_movie_modal
      .minimum_availability_list
      .set_items(MinimumAvailability::iter().collect());
    add_movie_modal
      .quality_profile_list
      .set_items(vec![quality_profile_name.clone()]);

    let mut add_movie_search_result_table = StatefulTable::default();
    add_movie_search_result_table.set_items(vec![add_movie_search_result()]);
    add_movie_search_result_table.sorting(vec![sort_option!(tmdb_id)]);
    add_movie_search_result_table.search = Some("something".into());
    add_movie_search_result_table.filter = Some("something".into());

    let mut edit_movie_modal = EditMovieModal {
      monitored: Some(true),
      path: "/nfs/movies".into(),
      tags: "alex".into(),
      ..EditMovieModal::default()
    };
    edit_movie_modal
      .minimum_availability_list
      .set_items(MinimumAvailability::iter().collect());
    edit_movie_modal
      .quality_profile_list
      .set_items(vec![quality_profile_name.clone()]);

    let mut edit_collection_modal = EditCollectionModal {
      monitored: Some(true),
      path: "/nfs/movies".into(),
      search_on_add: Some(true),
      ..EditCollectionModal::default()
    };
    edit_collection_modal
      .minimum_availability_list
      .set_items(MinimumAvailability::iter().collect());
    edit_collection_modal
      .quality_profile_list
      .set_items(vec![quality_profile_name.clone()]);

    let edit_indexer_modal = EditIndexerModal {
      name: "DrunkenSlug".into(),
      enable_rss: Some(true),
      enable_automatic_search: Some(true),
      enable_interactive_search: Some(true),
      url: "http://127.0.0.1:9696/1/".into(),
      api_key: "someApiKey".into(),
      seed_ratio: "ratio".into(),
      tags: "25".into(),
      priority: 1,
    };

    let indexer_settings = IndexerSettings {
      allow_hardcoded_subs: true,
      availability_delay: 0,
      id: 1,
      maximum_size: 1234,
      minimum_age: 12,
      prefer_indexer_flags: true,
      retention: 30,
      rss_sync_interval: 60,
      whitelisted_hardcoded_subs: "eng".into(),
    };

    let mut indexer_test_results = StatefulTable::default();
    indexer_test_results.set_items(vec![indexer_test_result()]);
    indexer_test_results.sorting(vec![sort_option!(name)]);
    indexer_test_results.search = Some("something".into());
    indexer_test_results.filter = Some("something".into());

    let mut movie_details_modal = MovieDetailsModal {
      movie_details: ScrollableText::with_string("Some information".to_owned()),
      file_details: "Some file info".to_owned(),
      audio_details: "Some audio info".to_owned(),
      video_details: "Some video info".to_owned(),
      ..MovieDetailsModal::default()
    };
    movie_details_modal
      .movie_history
      .set_items(vec![movie_history_item()]);
    movie_details_modal
      .movie_cast
      .set_items(vec![cast_credit()]);
    movie_details_modal
      .movie_crew
      .set_items(vec![crew_credit()]);
    movie_details_modal
      .movie_releases
      .set_items(vec![torrent_release(), usenet_release()]);
    movie_details_modal
      .movie_releases
      .sorting(vec![sort_option!(indexer_id)]);

    let mut radarr_data = RadarrData {
      disk_space_vec: vec![diskspace()],
      version: "1.2.3.4".to_owned(),
      quality_profile_map: quality_profile_map(),
      tags_map: tags_map(),
      updates: updates(),
      start_time: DateTime::from(DateTime::parse_from_rfc3339("2023-05-20T21:29:16Z").unwrap()),
      add_movie_search: Some("test".into()),
      add_movie_modal: Some(add_movie_modal),
      add_searched_movies: Some(add_movie_search_result_table),
      edit_movie_modal: Some(edit_movie_modal),
      edit_collection_modal: Some(edit_collection_modal),
      edit_indexer_modal: Some(edit_indexer_modal),
      edit_root_folder: Some("/nfs/movies".into()),
      indexer_settings: Some(indexer_settings),
      indexer_test_errors: Some("error".into()),
      indexer_test_all_results: Some(indexer_test_results),
      movie_details_modal: Some(movie_details_modal),
      delete_movie_files: true,
      ..RadarrData::default()
    };
    radarr_data.root_folders.set_items(vec![root_folder()]);
    radarr_data.movies.set_items(vec![movie()]);
    radarr_data.movies.sorting(vec![sort_option!(id)]);
    radarr_data.movies.search = Some("Something".into());
    radarr_data.movies.filter = Some("Something".into());
    radarr_data.collections.set_items(vec![collection()]);
    radarr_data.collections.sorting(vec![sort_option!(id)]);
    radarr_data.collections.search = Some("Something".into());
    radarr_data.collections.filter = Some("Something".into());
    radarr_data
      .collection_movies
      .set_items(vec![collection_movie()]);
    radarr_data.downloads.set_items(vec![download_record()]);
    radarr_data.blocklist.set_items(vec![blocklist_item()]);
    radarr_data.blocklist.sorting(vec![sort_option!(id)]);
    radarr_data.history.set_items(vec![radarr_history_item()]);
    radarr_data.history.sorting(vec![sort_option!(id)]);
    radarr_data.history.search = Some("Something".into());
    radarr_data.history.filter = Some("Something".into());
    radarr_data.indexers.set_items(vec![indexer()]);
    radarr_data.indexers.sorting(vec![sort_option!(id)]);
    radarr_data.indexers.search = Some("Something".into());
    radarr_data.indexers.filter = Some("Something".into());
    radarr_data.logs.set_items(vec![log_line().into()]);
    radarr_data.log_details.set_items(vec![log_line().into()]);
    radarr_data.tasks.set_items(vec![task()]);
    radarr_data.queued_events.set_items(vec![queued_event()]);

    radarr_data
  }
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, Default, EnumIter)]
#[cfg_attr(test, derive(Display, EnumString))]
pub enum ActiveRadarrBlock {
  AddMovieAlreadyInLibrary,
  AddMovieSearchInput,
  AddMovieSearchResults,
  AddMoviePrompt,
  AddMovieSelectMinimumAvailability,
  AddMovieSelectQualityProfile,
  AddMovieSelectMonitor,
  AddMovieSelectRootFolder,
  AddMovieConfirmPrompt,
  AddMovieTagsInput,
  AddMovieEmptySearchResults,
  AddRootFolderPrompt,
  AutomaticallySearchMoviePrompt,
  Blocklist,
  BlocklistClearAllItemsPrompt,
  BlocklistItemDetails,
  BlocklistSortPrompt,
  History,
  HistoryItemDetails,
  HistorySortPrompt,
  FilterHistory,
  FilterHistoryError,
  SearchHistory,
  SearchHistoryError,
  Collections,
  CollectionsSortPrompt,
  CollectionDetails,
  Cast,
  Crew,
  DeleteBlocklistItemPrompt,
  DeleteDownloadPrompt,
  DeleteIndexerPrompt,
  DeleteMoviePrompt,
  DeleteMovieConfirmPrompt,
  DeleteMovieToggleDeleteFile,
  DeleteMovieToggleAddListExclusion,
  DeleteRootFolderPrompt,
  Downloads,
  EditCollectionPrompt,
  EditCollectionConfirmPrompt,
  EditCollectionRootFolderPathInput,
  EditCollectionSelectMinimumAvailability,
  EditCollectionSelectQualityProfile,
  EditCollectionToggleSearchOnAdd,
  EditCollectionToggleMonitored,
  EditIndexerPrompt,
  EditIndexerConfirmPrompt,
  EditIndexerApiKeyInput,
  EditIndexerNameInput,
  EditIndexerSeedRatioInput,
  EditIndexerToggleEnableRss,
  EditIndexerToggleEnableAutomaticSearch,
  EditIndexerToggleEnableInteractiveSearch,
  EditIndexerPriorityInput,
  EditIndexerUrlInput,
  EditIndexerTagsInput,
  EditMoviePrompt,
  EditMovieConfirmPrompt,
  EditMoviePathInput,
  EditMovieSelectMinimumAvailability,
  EditMovieSelectQualityProfile,
  EditMovieTagsInput,
  EditMovieToggleMonitored,
  FileInfo,
  FilterCollections,
  FilterCollectionsError,
  FilterMovies,
  FilterMoviesError,
  Indexers,
  AllIndexerSettingsPrompt,
  IndexerSettingsAvailabilityDelayInput,
  IndexerSettingsConfirmPrompt,
  IndexerSettingsMaximumSizeInput,
  IndexerSettingsMinimumAgeInput,
  IndexerSettingsRetentionInput,
  IndexerSettingsRssSyncIntervalInput,
  IndexerSettingsToggleAllowHardcodedSubs,
  IndexerSettingsTogglePreferIndexerFlags,
  IndexerSettingsWhitelistedSubtitleTagsInput,
  ManualSearch,
  ManualSearchSortPrompt,
  ManualSearchConfirmPrompt,
  MovieDetails,
  MovieHistory,
  #[default]
  Movies,
  MoviesSortPrompt,
  RootFolders,
  System,
  SystemLogs,
  SystemQueuedEvents,
  SystemTasks,
  SystemTaskStartConfirmPrompt,
  SystemUpdates,
  TestIndexer,
  TestAllIndexers,
  UpdateAndScanPrompt,
  UpdateAllCollectionsPrompt,
  UpdateAllMoviesPrompt,
  UpdateDownloadsPrompt,
  SearchCollection,
  SearchCollectionError,
  SearchMovie,
  SearchMovieError,
  ViewMovieOverview,
}

pub static LIBRARY_BLOCKS: [ActiveRadarrBlock; 7] = [
  ActiveRadarrBlock::Movies,
  ActiveRadarrBlock::MoviesSortPrompt,
  ActiveRadarrBlock::SearchMovie,
  ActiveRadarrBlock::SearchMovieError,
  ActiveRadarrBlock::FilterMovies,
  ActiveRadarrBlock::FilterMoviesError,
  ActiveRadarrBlock::UpdateAllMoviesPrompt,
];
pub static COLLECTIONS_BLOCKS: [ActiveRadarrBlock; 7] = [
  ActiveRadarrBlock::Collections,
  ActiveRadarrBlock::CollectionsSortPrompt,
  ActiveRadarrBlock::SearchCollection,
  ActiveRadarrBlock::SearchCollectionError,
  ActiveRadarrBlock::FilterCollections,
  ActiveRadarrBlock::FilterCollectionsError,
  ActiveRadarrBlock::UpdateAllCollectionsPrompt,
];
pub static INDEXERS_BLOCKS: [ActiveRadarrBlock; 3] = [
  ActiveRadarrBlock::DeleteIndexerPrompt,
  ActiveRadarrBlock::Indexers,
  ActiveRadarrBlock::TestIndexer,
];
pub static ROOT_FOLDERS_BLOCKS: [ActiveRadarrBlock; 3] = [
  ActiveRadarrBlock::RootFolders,
  ActiveRadarrBlock::AddRootFolderPrompt,
  ActiveRadarrBlock::DeleteRootFolderPrompt,
];
pub static BLOCKLIST_BLOCKS: [ActiveRadarrBlock; 5] = [
  ActiveRadarrBlock::Blocklist,
  ActiveRadarrBlock::BlocklistItemDetails,
  ActiveRadarrBlock::DeleteBlocklistItemPrompt,
  ActiveRadarrBlock::BlocklistClearAllItemsPrompt,
  ActiveRadarrBlock::BlocklistSortPrompt,
];
pub static HISTORY_BLOCKS: [ActiveRadarrBlock; 7] = [
  ActiveRadarrBlock::History,
  ActiveRadarrBlock::HistoryItemDetails,
  ActiveRadarrBlock::HistorySortPrompt,
  ActiveRadarrBlock::FilterHistory,
  ActiveRadarrBlock::FilterHistoryError,
  ActiveRadarrBlock::SearchHistory,
  ActiveRadarrBlock::SearchHistoryError,
];
pub static ADD_MOVIE_BLOCKS: [ActiveRadarrBlock; 10] = [
  ActiveRadarrBlock::AddMovieSearchInput,
  ActiveRadarrBlock::AddMovieSearchResults,
  ActiveRadarrBlock::AddMovieEmptySearchResults,
  ActiveRadarrBlock::AddMoviePrompt,
  ActiveRadarrBlock::AddMovieSelectMinimumAvailability,
  ActiveRadarrBlock::AddMovieSelectMonitor,
  ActiveRadarrBlock::AddMovieSelectQualityProfile,
  ActiveRadarrBlock::AddMovieSelectRootFolder,
  ActiveRadarrBlock::AddMovieAlreadyInLibrary,
  ActiveRadarrBlock::AddMovieTagsInput,
];
pub const ADD_MOVIE_SELECTION_BLOCKS: &[&[ActiveRadarrBlock]] = &[
  &[ActiveRadarrBlock::AddMovieSelectRootFolder],
  &[ActiveRadarrBlock::AddMovieSelectMonitor],
  &[ActiveRadarrBlock::AddMovieSelectMinimumAvailability],
  &[ActiveRadarrBlock::AddMovieSelectQualityProfile],
  &[ActiveRadarrBlock::AddMovieTagsInput],
  &[ActiveRadarrBlock::AddMovieConfirmPrompt],
];
pub static EDIT_COLLECTION_BLOCKS: [ActiveRadarrBlock; 7] = [
  ActiveRadarrBlock::EditCollectionPrompt,
  ActiveRadarrBlock::EditCollectionConfirmPrompt,
  ActiveRadarrBlock::EditCollectionRootFolderPathInput,
  ActiveRadarrBlock::EditCollectionSelectMinimumAvailability,
  ActiveRadarrBlock::EditCollectionSelectQualityProfile,
  ActiveRadarrBlock::EditCollectionToggleSearchOnAdd,
  ActiveRadarrBlock::EditCollectionToggleMonitored,
];
pub const EDIT_COLLECTION_SELECTION_BLOCKS: &[&[ActiveRadarrBlock]] = &[
  &[ActiveRadarrBlock::EditCollectionToggleMonitored],
  &[ActiveRadarrBlock::EditCollectionSelectMinimumAvailability],
  &[ActiveRadarrBlock::EditCollectionSelectQualityProfile],
  &[ActiveRadarrBlock::EditCollectionRootFolderPathInput],
  &[ActiveRadarrBlock::EditCollectionToggleSearchOnAdd],
  &[ActiveRadarrBlock::EditCollectionConfirmPrompt],
];
pub static EDIT_MOVIE_BLOCKS: [ActiveRadarrBlock; 7] = [
  ActiveRadarrBlock::EditMoviePrompt,
  ActiveRadarrBlock::EditMovieConfirmPrompt,
  ActiveRadarrBlock::EditMoviePathInput,
  ActiveRadarrBlock::EditMovieSelectMinimumAvailability,
  ActiveRadarrBlock::EditMovieSelectQualityProfile,
  ActiveRadarrBlock::EditMovieTagsInput,
  ActiveRadarrBlock::EditMovieToggleMonitored,
];
pub const EDIT_MOVIE_SELECTION_BLOCKS: &[&[ActiveRadarrBlock]] = &[
  &[ActiveRadarrBlock::EditMovieToggleMonitored],
  &[ActiveRadarrBlock::EditMovieSelectMinimumAvailability],
  &[ActiveRadarrBlock::EditMovieSelectQualityProfile],
  &[ActiveRadarrBlock::EditMoviePathInput],
  &[ActiveRadarrBlock::EditMovieTagsInput],
  &[ActiveRadarrBlock::EditMovieConfirmPrompt],
];
pub static DOWNLOADS_BLOCKS: [ActiveRadarrBlock; 3] = [
  ActiveRadarrBlock::Downloads,
  ActiveRadarrBlock::DeleteDownloadPrompt,
  ActiveRadarrBlock::UpdateDownloadsPrompt,
];
pub static MOVIE_DETAILS_BLOCKS: [ActiveRadarrBlock; 10] = [
  ActiveRadarrBlock::MovieDetails,
  ActiveRadarrBlock::MovieHistory,
  ActiveRadarrBlock::FileInfo,
  ActiveRadarrBlock::Cast,
  ActiveRadarrBlock::Crew,
  ActiveRadarrBlock::AutomaticallySearchMoviePrompt,
  ActiveRadarrBlock::UpdateAndScanPrompt,
  ActiveRadarrBlock::ManualSearch,
  ActiveRadarrBlock::ManualSearchSortPrompt,
  ActiveRadarrBlock::ManualSearchConfirmPrompt,
];
pub static COLLECTION_DETAILS_BLOCKS: [ActiveRadarrBlock; 2] = [
  ActiveRadarrBlock::CollectionDetails,
  ActiveRadarrBlock::ViewMovieOverview,
];
pub static DELETE_MOVIE_BLOCKS: [ActiveRadarrBlock; 4] = [
  ActiveRadarrBlock::DeleteMoviePrompt,
  ActiveRadarrBlock::DeleteMovieConfirmPrompt,
  ActiveRadarrBlock::DeleteMovieToggleDeleteFile,
  ActiveRadarrBlock::DeleteMovieToggleAddListExclusion,
];
pub const DELETE_MOVIE_SELECTION_BLOCKS: &[&[ActiveRadarrBlock]] = &[
  &[ActiveRadarrBlock::DeleteMovieToggleDeleteFile],
  &[ActiveRadarrBlock::DeleteMovieToggleAddListExclusion],
  &[ActiveRadarrBlock::DeleteMovieConfirmPrompt],
];
pub static EDIT_INDEXER_BLOCKS: [ActiveRadarrBlock; 11] = [
  ActiveRadarrBlock::EditIndexerPrompt,
  ActiveRadarrBlock::EditIndexerConfirmPrompt,
  ActiveRadarrBlock::EditIndexerApiKeyInput,
  ActiveRadarrBlock::EditIndexerNameInput,
  ActiveRadarrBlock::EditIndexerSeedRatioInput,
  ActiveRadarrBlock::EditIndexerToggleEnableRss,
  ActiveRadarrBlock::EditIndexerToggleEnableAutomaticSearch,
  ActiveRadarrBlock::EditIndexerToggleEnableInteractiveSearch,
  ActiveRadarrBlock::EditIndexerPriorityInput,
  ActiveRadarrBlock::EditIndexerUrlInput,
  ActiveRadarrBlock::EditIndexerTagsInput,
];
pub const EDIT_INDEXER_TORRENT_SELECTION_BLOCKS: &[&[ActiveRadarrBlock]] = &[
  &[
    ActiveRadarrBlock::EditIndexerNameInput,
    ActiveRadarrBlock::EditIndexerUrlInput,
  ],
  &[
    ActiveRadarrBlock::EditIndexerToggleEnableRss,
    ActiveRadarrBlock::EditIndexerApiKeyInput,
  ],
  &[
    ActiveRadarrBlock::EditIndexerToggleEnableAutomaticSearch,
    ActiveRadarrBlock::EditIndexerSeedRatioInput,
  ],
  &[
    ActiveRadarrBlock::EditIndexerToggleEnableInteractiveSearch,
    ActiveRadarrBlock::EditIndexerTagsInput,
  ],
  &[
    ActiveRadarrBlock::EditIndexerPriorityInput,
    ActiveRadarrBlock::EditIndexerConfirmPrompt,
  ],
  &[
    ActiveRadarrBlock::EditIndexerConfirmPrompt,
    ActiveRadarrBlock::EditIndexerConfirmPrompt,
  ],
];
pub const EDIT_INDEXER_NZB_SELECTION_BLOCKS: &[&[ActiveRadarrBlock]] = &[
  &[
    ActiveRadarrBlock::EditIndexerNameInput,
    ActiveRadarrBlock::EditIndexerUrlInput,
  ],
  &[
    ActiveRadarrBlock::EditIndexerToggleEnableRss,
    ActiveRadarrBlock::EditIndexerApiKeyInput,
  ],
  &[
    ActiveRadarrBlock::EditIndexerToggleEnableAutomaticSearch,
    ActiveRadarrBlock::EditIndexerTagsInput,
  ],
  &[
    ActiveRadarrBlock::EditIndexerToggleEnableInteractiveSearch,
    ActiveRadarrBlock::EditIndexerPriorityInput,
  ],
  &[
    ActiveRadarrBlock::EditIndexerConfirmPrompt,
    ActiveRadarrBlock::EditIndexerConfirmPrompt,
  ],
];
pub static INDEXER_SETTINGS_BLOCKS: [ActiveRadarrBlock; 10] = [
  ActiveRadarrBlock::AllIndexerSettingsPrompt,
  ActiveRadarrBlock::IndexerSettingsAvailabilityDelayInput,
  ActiveRadarrBlock::IndexerSettingsConfirmPrompt,
  ActiveRadarrBlock::IndexerSettingsMaximumSizeInput,
  ActiveRadarrBlock::IndexerSettingsMinimumAgeInput,
  ActiveRadarrBlock::IndexerSettingsRetentionInput,
  ActiveRadarrBlock::IndexerSettingsRssSyncIntervalInput,
  ActiveRadarrBlock::IndexerSettingsToggleAllowHardcodedSubs,
  ActiveRadarrBlock::IndexerSettingsTogglePreferIndexerFlags,
  ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput,
];
pub const INDEXER_SETTINGS_SELECTION_BLOCKS: &[&[ActiveRadarrBlock]] = &[
  &[
    ActiveRadarrBlock::IndexerSettingsMinimumAgeInput,
    ActiveRadarrBlock::IndexerSettingsAvailabilityDelayInput,
  ],
  &[
    ActiveRadarrBlock::IndexerSettingsRetentionInput,
    ActiveRadarrBlock::IndexerSettingsRssSyncIntervalInput,
  ],
  &[
    ActiveRadarrBlock::IndexerSettingsMaximumSizeInput,
    ActiveRadarrBlock::IndexerSettingsWhitelistedSubtitleTagsInput,
  ],
  &[
    ActiveRadarrBlock::IndexerSettingsTogglePreferIndexerFlags,
    ActiveRadarrBlock::IndexerSettingsToggleAllowHardcodedSubs,
  ],
  &[
    ActiveRadarrBlock::IndexerSettingsConfirmPrompt,
    ActiveRadarrBlock::IndexerSettingsConfirmPrompt,
  ],
];
pub static SYSTEM_DETAILS_BLOCKS: [ActiveRadarrBlock; 5] = [
  ActiveRadarrBlock::SystemLogs,
  ActiveRadarrBlock::SystemQueuedEvents,
  ActiveRadarrBlock::SystemTasks,
  ActiveRadarrBlock::SystemTaskStartConfirmPrompt,
  ActiveRadarrBlock::SystemUpdates,
];

impl From<ActiveRadarrBlock> for Route {
  fn from(active_radarr_block: ActiveRadarrBlock) -> Route {
    Route::Radarr(active_radarr_block, None)
  }
}

impl From<(ActiveRadarrBlock, Option<ActiveRadarrBlock>)> for Route {
  fn from(value: (ActiveRadarrBlock, Option<ActiveRadarrBlock>)) -> Route {
    Route::Radarr(value.0, value.1)
  }
}
