//
//  Options.swift
//  ABCBluetoothDemo
//
//  Created by AB Circle on 30/4/2021.
//  Copyright © 2020-2024 AB Circle. All rights reserved.
//

import Foundation

/// Class holding option values set in the Options View & used everywhere else in the app
class Options {
    /// Flag indicating if default key should be used.
    private var optionUseDefaultKey: Bool   = true
    /// Custom key string
    private var optionCustomKey:     String = ""
    /// Name filter for scanBluetooth
    private var optionNameFilter:    String = ""
    /// RSSI filter for scanBluetooth
    private var optionRssiFilter:    Int    = 0
    /// CardTerminal monitor refresh rate
    private var optionRefreshRate:   UInt16 = 0
    /// CardTerminal monitor battery threshold
    private var optionThreshold:     UInt8  = 0
    /// Flag indicating if ACK protocol for Card Terminals should be enabled or not
    /// (for terminals with firmware 109.00 or higher only)
    private var optionACKEnabled:    Bool    = false
    
    /// Get or set flag indicating if default key should be used.
    var useDefaultKey: Bool {
        get {
            return optionUseDefaultKey
        }
        set(useDefaultKey) {
            optionUseDefaultKey = useDefaultKey
        }
    }
    
    /// Get or set custom key string
    var customKeyString: String {
        get {
            return optionCustomKey
        }
        set(customKeyString) {
            optionCustomKey = customKeyString
        }
    }
    
    /// Get or set Name filter for scanBluetooth
    var nameFilter: String {
        get {
            return optionNameFilter
        }
        set(namefilter) {
            optionNameFilter = namefilter
        }
    }
    
    /// Get or set RSSI filter for scanBluetooth
    var rssiFilter: Int {
        get {
            return optionRssiFilter
        }
        set(rssiFilter) {
            optionRssiFilter = rssiFilter
        }
    }
    
    /// Get or set CardTerminal monitor refresh rate
    var monitorRefreshRate: UInt16 {
        get {
            return optionRefreshRate
        }
        set(refreshRate) {
            optionRefreshRate = refreshRate
        }
    }
    
    /// Get or set CardTerminal monitor battery threshold
    var monitorBatteryThreshold: UInt8 {
        get {
            return optionThreshold
        }
        
        set(batteryThreshold) {
            optionThreshold = batteryThreshold
        }
    }
    
    /// Get or set ACK Protocol Enabled flag
    var ackEnabled: Bool {
        get {
            return optionACKEnabled
        }
        
        set(ackEnabled) {
            optionACKEnabled = ackEnabled
        }
    }
    
    /// Set all options from another Options instance
    ///
    /// - Parameter newOptions: new options to set
    func set(newOptions: Options) {
        optionThreshold     = newOptions.monitorBatteryThreshold
        optionRefreshRate   = newOptions.monitorRefreshRate
        optionRssiFilter    = newOptions.rssiFilter
        optionNameFilter    = newOptions.nameFilter
        optionCustomKey     = newOptions.customKeyString
        optionUseDefaultKey = newOptions.useDefaultKey
        optionACKEnabled    = newOptions.ackEnabled
    }
}
