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

import Foundation

class GetMessage {
    var sessionGetMessage = SessionGetMessage()

    func start() {
        print(debug: "called")
        sessionGetMessage.RequestGetMessage { response in
            switch response {
            case .success(let resultData):
                let serverSession = ServerSession()
                let resjson = serverSession.fromJSON(resultData: resultData, resltType: ResGetMessages.self)
                if let res = resjson {
                    if res.mode == 1 {
                        SharingData.message.mode = true
                    } else {
                        SharingData.message.mode = false
                    }
                    SharingData.message.messages = []
                    if let msg = res.messages {
                        SharingData.message.messages = msg
                    }
                }
            case .failure(let errorCode):
                print(debug: errorCode)
                break
            }
        }
    }
}

