//
//  GetMessage.swift
//  Sailassist
//
//  Created by 三浦薫巳 on 2023/11/14.
//

import Foundation

class GetMessage {
    var sessionGetMessage = SessionGetMessage()

    func start() {
        print(debug: "called")
        sessionGetMessage.RequestGetMessage(responseGetMessage)
    }

    private func responseGetMessage(result: Result<Data, APIError>) {
        print(debug: "called")
        switch result {
        case .success(let resultData):
            let serverSession = ServerSession()
            let resjson = serverSession.fromJSON(resultData: resultData, resltType: ResGetMessages.self)
            if let res = resjson {
                SharingData.message.mode = res.mode
                SharingData.message.messages = []
                if let msg = res.messages {
                    SharingData.message.messages = msg
                }
            }
        case .failure(let errorCode):
            print(debug: errorCode)
            break
        }
    }
}

