//
//  Preferences.swift
//  forShip
//
//  Created by Mamoru Sugita on 2023/10/16.
//

import Foundation
import SwiftUI

class Preferences{
    @AppStorage(PreferencesKey.TypeInt.LastLoginDate.rawValue) private static var lastLoginDate: Date?
    static var lastLoginDate_Int64 : Int64?{
        get{
            if let date = lastLoginDate{
                DateTextLib.Date2UnixTime(date: date)
            }else{
                nil
            }
        }
        set{
            lastLoginDate = DateTextLib.UnixTime2Date(newValue ?? 0)
        }
    }
    
//    func getPreferences(key)
}


//Date型をAppStorageに保存できるように拡張
extension Date: RawRepresentable {
    public var rawValue: String {
        self.timeIntervalSinceReferenceDate.description
    }
    
    public init?(rawValue: String) {
        self = Date(timeIntervalSinceReferenceDate: Double(rawValue) ?? 0.0)
    }
}
