//
//  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
        }
    }
}

