package eu.friedcutlet.yokan.database import kotlinx.serialization.Serializable @Serializable data class DbLibraryPreferences( /** Missing = ask, zero = uncategorized, positive = a category of the same media type. */ val defaultCategoryIds: Map = emptyMap(), val groupingByType: Map = emptyMap(), val categoryPreferences: Map> = emptyMap(), val extraFilters: Map = emptyMap(), val randomSeeds: Map = emptyMap(), val updateRulesByType: Map = emptyMap(), val updateGroupModes: Map = emptyMap(), val deviceConstraints: DbAutomaticUpdateConstraints = DbAutomaticUpdateConstraints(), /** Animetail "Set as default" chapter/episode list settings; missing = built-in default. */ val chapterListDefaults: Map = emptyMap(), /** Per-title episode filler filter (title id → 1 only filler, 2 hide filler); missing = media type default. */ val chapterFillerFilters: Map = emptyMap(), ) { fun chapterListDefault(type: DbItemType) = chapterListDefaults[type] ?: DbChapterListDefaults() fun withChapterListDefault(type: DbItemType, defaults: DbChapterListDefaults) = copy( chapterListDefaults = if (defaults == DbChapterListDefaults()) chapterListDefaults - type else chapterListDefaults + (type to defaults), ) fun updateRules(type: DbItemType) = updateRulesByType[type] ?: DbSmartUpdateRules() fun updateGroupMode(type: DbItemType) = updateGroupModes[type] ?: DbGroupUpdateMode.Global fun withUpdateRules(type: DbItemType, rules: DbSmartUpdateRules) = copy( updateRulesByType = if (rules == DbSmartUpdateRules()) updateRulesByType - type else updateRulesByType + (type to rules), ) fun withUpdateGroupMode(type: DbItemType, mode: DbGroupUpdateMode) = copy( updateGroupModes = if (mode == DbGroupUpdateMode.Global) updateGroupModes - type else updateGroupModes + (type to mode), ) fun grouping(type: DbItemType): DbLibraryGrouping = groupingByType[type] ?: DbLibraryGrouping.Categories fun categories(type: DbItemType): Map = categoryPreferences[type].orEmpty() fun filters(type: DbItemType): DbLibraryExtraFilters = extraFilters[type] ?: DbLibraryExtraFilters() fun withFilters(type: DbItemType, filters: DbLibraryExtraFilters): DbLibraryPreferences = copy( extraFilters = if (filters == DbLibraryExtraFilters()) extraFilters - type else extraFilters + (type to filters), ) fun withGrouping(type: DbItemType, grouping: DbLibraryGrouping): DbLibraryPreferences = copy( groupingByType = if (grouping == DbLibraryGrouping.Categories) groupingByType - type else groupingByType + (type to grouping), ) fun withCategory(type: DbItemType, id: Long, preferences: DbCategoryLibraryPreferences?): DbLibraryPreferences { val updated = if (preferences == null) categories(type) - id else categories(type) + (id to preferences) return copy(categoryPreferences = if (updated.isEmpty()) categoryPreferences - type else categoryPreferences + (type to updated)) } fun defaultCategory(type: DbItemType): Long? = defaultCategoryIds[type]?.takeIf { it >= 0 } fun withDefaultCategory(type: DbItemType, id: Long?): DbLibraryPreferences = copy( defaultCategoryIds = if (id == null || id < 0) defaultCategoryIds - type else defaultCategoryIds + (type to id), ) } @Serializable data class DbSmartUpdateRules( val skipCompleted: Boolean = false, val onlyCaughtUp: Boolean = false, val onlyStarted: Boolean = false, /** Preserve Yokan's existing automatic/manual cadence by default. */ val respectExpectedReleasePeriod: Boolean = true, ) /** Used by titles without their own sort/filter entry. Filters: 0 off, 1 only matching, 2 exclude matching. */ @Serializable data class DbChapterListDefaults( val sortIndex: Int = 1, val sortReverse: Boolean = false, val downloaded: Int = 0, val unread: Int = 0, val bookmarked: Int = 0, val filler: Int = 0, ) @Serializable enum class DbGroupUpdateMode { Global, CurrentGroup, CurrentExceptUngrouped } @Serializable data class DbLibraryExtraFilters( /** Off = absent; 1 = include any selected provider, 2 = exclude every selected provider. */ val providerTracking: Map = emptyMap(), val customInterval: Int = 0, ) @Serializable enum class DbLibraryGrouping { Categories, Source, Status, TrackerStatus, Tags, Ungrouped } @Serializable data class DbCategoryLibraryPreferences( val sort: DbSortLibraryManga? = null, val display: DbCategoryLibraryDisplay? = null, ) /** Tabs and library-wide counts remain global; these options affect cards in one category. */ @Serializable data class DbCategoryLibraryDisplay( val displayType: DbDisplayType = DbDisplayType.ComfortableGrid, val gridSize: Int = 0, val downloadBadges: Boolean = true, val language: Boolean = false, val source: Boolean = false, val localBadge: Boolean = true, val continueButton: Boolean = true, )