//
//  GetPushHistory.swift
//  Sailassist
//
//  Created by 三浦薫巳 on 2023/12/02.
//

import Foundation

class GetPushHistory {
    var sessionPushHistory = SessionPushHistory()

    func start() {
        print(debug: "called")
        sessionPushHistory.RequestPushHistory(responsePushHistory)
    }

    private func responsePushHistory(result: Result<Data, APIError>) {
        print(debug: "called")
        switch result {
        case .success(let resultData):
            let serverSession = ServerSession()
            let resjson = serverSession.fromJSON(resultData: resultData, resltType: [ResPushHistory].self)
            if let res = resjson {
                for push in res {
                    if let id = push.id {
                        SharingData.pushHistory.setPushHistory(key: id, value: push)
                    }
                }
            }
        case .failure(let errorCode):
            print(debug: errorCode)
            break
        }
    }
}
