//
//  ContentSettingsViewModel.swift
//  SodaLive
//
//  Created by klaus on 10/10/24.
//

import Foundation

final class ContentSettingsViewModel: ObservableObject {
    @Published var isAdultContentVisible = UserDefaults.isAdultContentVisible() {
        didSet {
            if oldValue != isAdultContentVisible {
                UserDefaults.set(isAdultContentVisible, forKey: .isAdultContentVisible)
                AppState.shared.isChangeAdultContentVisible = true
                
                if !isAdultContentVisible {
                    adultContentPreference = .ALL
                    UserDefaults.set(ContentType.ALL.rawValue, forKey: .contentPreference)
                }
            }
        }
    }
    
    @Published var adultContentPreference = ContentType(rawValue: UserDefaults.string(forKey: .contentPreference)) ?? ContentType.ALL {
        didSet {
            if oldValue != adultContentPreference {
                UserDefaults.set(adultContentPreference.rawValue, forKey: .contentPreference)
                AppState.shared.isChangeAdultContentVisible = true
            }
        }
    }
}
