//
//  SharingData.swift
//  forShip
//
//  Created by Mamoru Sugita on 2023/10/20.
//
import Foundation
import CoreLocation

class SharingData{
    
    static var my = My()
    class My: ObservableObject {
        @Published var location: CLLocationCoordinate2D? = .init(latitude: 0, longitude: 0)
        @Published var gps: CLLocationCoordinate2D? = nil
        @Published var server: CLLocationCoordinate2D? = nil
        @Published var speed: Double = 0.0
        @Published var course: Double = 0.0
        @Published var heading: Double = 0.0
        @Published var dataTime: String = "" //2023-11-02T05:25:49.4362123Z

        @Published var id: Int = 0
        @Published var shipId: Int = 0
        @Published var shipName: String = ""
        @Published var imo: Int = 0
        @Published var mmsi: Int = 0
        
        func setLocation(_ location: CLLocationCoordinate2D?){
            self.location = location
        }

        func reset() {
            location = nil
            speed = 0.0
            course = 0.0
            heading = 0.0
        }
    }

    static var map = Map()
    class Map: ObservableObject {
        @Published var wayPoints: [CLLocationCoordinate2D] = []
        @Published var legLine: [CLLocationCoordinate2D] = []
        @Published var portLine: [CLLocationCoordinate2D] = []
        @Published var starboardLine: [CLLocationCoordinate2D] = []
    }

    static var message = Message()
    class Message: ObservableObject {
        @Published var mode: Int = 0   // 0:通常 , 1:Warning中
        @Published var messages: [ChatMessage] = [
            ChatMessage(
                shipId: 10000003,
                messageId: "92c2dfb5-f5ed-4943-98a3-9848d7f9a962",
                type: 0,
                time: "2023-10-06T01:51:01.872Z",
                location: 1,
                from: "はだだ",
                fromId: "487420489",
                message: "999",
                stampId: 0,
                viewer: [
                    Viewer(
                        time: "2023-10-06T01:51:12.973Z",
                        location: 1,
                        id: ""),
                    Viewer(
                        time: "2023-10-06T01:51:12.973Z",
                        location: 2,
                        id: "")
                ]
            ),
            ChatMessage(
                shipId: 10000001,
                messageId: "92c2dfb5-f5ed-4943-98a3-a848d7f9a962",
                type: 0,
                time: "2023-10-06T01:51:01.872Z",
                location: 1,
                from: "はだだ",
                fromId: "487420489",
                message: "999",
                stampId: 0,
                viewer: [
                    Viewer(
                        time: "2023-10-06T01:51:12.973Z",
                        location: 1,
                        id: ""),
                    Viewer(
                        time: "2023-10-06T01:51:12.973Z",
                        location: 2,
                        id: "")
                ]
            ),
        
        ]
        
        
    }

    /**
     * Eca
     */
    static var eca = Eca()
    class Eca: ObservableObject{
        @Published var ecaArea: Dictionary<String, RegisteredEca> = [:]
        
        func editEcaArea(key: String, value: RegisteredEca){
            ecaArea.updateValue(value, forKey: key)
        }
    }
    
    
}
