// // ModelColorConfiguration.swift // VDS // // Created by Matt Bruce on 8/4/22. // import Foundation import UIKit public protocol Colorable: Withable, Initable { associatedtype ModelType func getColor(_ viewModel: ModelType) -> UIColor } public protocol BinaryColorable{ var userTrueColor: Bool { get } } /// Meant to be used in a Object that implements the following interfaces for 2 possible color combinations /// - Surfaceable (var surface: Surface) /// /// let model = TestModel() /// model.surface = .light /// /// let config = SurfaceColorConfiguration() /// /// config.lightColor = .black /// config.darkColor = .white /// /// let textColor = config.getColor(model) //returns .black open class SurfaceColorConfiguration: Colorable { public var lightColor: UIColor = .clear public var darkColor: UIColor = .clear required public init(){} public func getColor(_ viewModel: ModelType) -> UIColor { return viewModel.surface == .light ? lightColor : darkColor } } /// Meant to be used in a Object that implements the following interfaces for 4 possible color combinations /// - Disabling (var disabled: Bool) /// - Surfaceable (var surface: Surface) /// /// let model = TestModel() /// model.surface = .dark /// model.disabled = false /// /// let config = DisabledSurfaceColorConfiguration() /// /// //disabled == false /// config.enabled.lightColor = .black /// config.enabled.darkColor = .white /// /// //disabled == true /// config.disabled.lightColor = .gray /// config.disabled.darkColor = .lightGray /// /// let textColor = config.getColor(model) //returns .white /// /// open class DisabledSurfaceColorConfiguration: Colorable { public var disabled = SurfaceColorConfiguration() public var enabled = SurfaceColorConfiguration() required public init(){} public func getColor(_ viewModel: ModelType) -> UIColor { return viewModel.disabled ? disabled.getColor(viewModel) : enabled.getColor(viewModel) } } /// Meant to be used in a Object that implements the following interfaces for 4 possible color combinations /// - BinaryColorable (var userTrueColor: Bool) /// - Surfaceable (var surface: Surface) /// /// let model = TestModel() /// model.surface = .dark /// model.on = true //this is read in the extension var userTrueColor /// let config = BinarySurfaceColorConfiguration() /// /// //True from BinaryColorable.userTrueColor /// config.forTrue.lightColor = .black /// config.forTrue.darkColor = .white /// /// //False from BinaryColorable.userTrueColor /// config.forFalse.lightColor = .red /// config.forFalse.darkColor = .red /// /// let textColor = config.getColor(model) //returns .white /// /// open class BinarySurfaceColorConfiguration: Colorable{ public var forTrue = SurfaceColorConfiguration() public var forFalse = SurfaceColorConfiguration() required public init(){} public func getColor(_ viewModel: ModelType) -> UIColor { return viewModel.userTrueColor ? forTrue.getColor(viewModel) : forFalse.getColor(viewModel) } } /// Meant to be used in a Object that implements the following interfaces for 8 possible color combinations /// - BinaryColorable (var userTrueColor: Bool) /// - Disabling (var disabled: Bool) /// - Surfaceable (var surface: Surface) /// /// let model = TestModel() /// model. /// let config = BinaryDisabledSurfaceColorConfiguration() /// /// //True /// config.forTrue.enabled.lightColor = .black /// config.forTrue.enabled.darkColor = .white /// config.forTrue.disabled.lightColor = .darkGray /// config.forTrue.disabled.darkColor = .lightGray /// /// //False /// config.forFalse.enabled.lightColor = .red /// config.forFalse.enabled.darkColor = .red /// config.forFalse.disabled.lightColor =.darkGray /// config.forFalse.disabled.darkColor = .lightGray /// /// let textColor = config.getColor(model) /// /// open class BinaryDisabledSurfaceColorConfiguration: Colorable { public var forTrue = DisabledSurfaceColorConfiguration() public var forFalse = DisabledSurfaceColorConfiguration() required public init(){} public func getColor(_ viewModel: ModelType) -> UIColor { return viewModel.userTrueColor ? forTrue.getColor(viewModel) : forFalse.getColor(viewModel) } }