//
//  UserData.swift
//  OrderScheduling
//
//  Created by 中道 on 2023/8/7.
//

import Foundation

public let USER = UserData.default

open class UserData {
    public static let `default` = UserData()
    
    public var isLogin : Bool {
        if token?.isEmpty == false {
            return true
        }
        return false
    }
    
    public var token : String? {
        return UserDefaults.standard.object(forKey: token_key) as? String
    }
    
    func setToken(token:String?) {
        UserDefaults.standard.set(token, forKey: token_key)
    }
    
    public var refreshToken : String? {
        return UserDefaults.standard.object(forKey: refresh_token_key) as? String
    }
    
    public func setRefreshToken(token: String?) {
        UserDefaults.standard.set(token, forKey: refresh_token_key)
    }
    
    public var supplierName : String? {
        return UserDefaults.standard.object(forKey: supplierName_key) as? String
    }
    
    func setSupplierName(supplierName:String?) {
        UserDefaults.standard.set(supplierName, forKey: supplierName_key)
    }
    
    public var phone : String? {
        return UserDefaults.standard.object(forKey: phone_key) as? String
    }
    
    func setPhone(phone:String?) {
        UserDefaults.standard.set(phone, forKey: phone_key)
    }
    
    public var supplierType : Int? {
        return UserDefaults.standard.object(forKey: supplierType_key) as? Int
    }
    
    func setSupplierType(supplierType:Int?) {
        UserDefaults.standard.set(supplierType, forKey: supplierType_key)
    }
    
    public var deviceToken : String?

    public var regId : String?

    func clear() {
        setToken(token: nil)
        setSupplierType(supplierType: nil)
    }
}
