//
//  NotificationSettingsDialogViewModel.swift
//  SodaLive
//
//  Created by klaus on 2023/08/11.
//

import Foundation
import Combine

final class NotificationSettingsDialogViewModel: ObservableObject {
    
    private let userRepository = UserRepository()
    private var subscription = Set<AnyCancellable>()
    
    @Published var live = true
    @Published var uploadContent = true
    @Published var message = true
    
    func submit() {
        userRepository
            .updateNotificationSettings(live: live, uploadContent: uploadContent, message: message)
            .sink { result in
                switch result {
                case .finished:
                    DEBUG_LOG("finish")
                case .failure(let error):
                    ERROR_LOG(error.localizedDescription)
                }
            } receiveValue: { _ in
                AppState.shared.isShowNotificationSettingsDialog = false
            }
            .store(in: &subscription)
    }
}