//
//  GerStoryViewsManager.swift
//  WoWonder
//
//  Created by UnikApp on 25/02/23.
//  Copyright © 2023 ScriptSun. All rights reserved.
//

import Foundation
import Alamofire
import WowonderMessengerSDK

class GerStoryViewsManager {
    
    static let instance = GerStoryViewsManager()
    
    func getStoryViews(story_id: String, session_Token: String, _ completionBlock: @escaping (Result<GetStoryViewModel, Error>) -> Void) {
        
        let params = [
            API.Params.story_id : story_id,
            API.Params.server_key : API.SERVER_KEY.Server_Key
            ] as [String : Any]
        
        AF.request(API.baseURL + "/api/get_story_views?access_token=" + session_Token, method: .post, parameters: params, encoding: URLEncoding.default, headers: nil).responseData { (response) in
            
            if (response.value != nil) {
                switch response.result {
                case .success(let data):
                    do {
                        let object = try JSONDecoder().decode(GetStoryViewModel.self, from: data)
                        completionBlock(.success(object))
                    } catch {
                        completionBlock(.failure(error))
                    }
                    break
                    
                case .failure(let error):
                    completionBlock(.failure(error))
                    break
                }
            }
        }
    }
}
