// // ModelColorConfiguration.swift // VDS // // Created by Matt Bruce on 8/4/22. // import Foundation import UIKit public protocol Colorable { 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 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() 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.isTrue.lightColor = .black /// config.isTrue.darkColor = .white /// /// //False from BinaryColorable.userTrueColor /// config.isFalse.lightColor = .red /// config.isFalse.darkColor = .red /// /// let textColor = config.getColor(model) //returns .white /// /// open class BinarySurfaceColorConfiguration: Colorable{ public var isTrue = SurfaceColorConfiguration() public var isFalse = SurfaceColorConfiguration() public func getColor(_ viewModel: ModelType) -> UIColor { return viewModel.userTrueColor ? isTrue.getColor(viewModel) : isFalse.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.isTrue.enabled.lightColor = .black /// config.isTrue.enabled.darkColor = .white /// config.isTrue.disabled.lightColor = .darkGray /// config.isTrue.disabled.darkColor = .lightGray /// /// //False /// config.isFalse.enabled.lightColor = .red /// config.isFalse.enabled.darkColor = .red /// config.isFalse.disabled.lightColor =.darkGray /// config.isFalse.disabled.darkColor = .lightGray /// /// let textColor = config.getColor(model) /// /// open class BinaryDisabledSurfaceColorConfiguration: Colorable { public var isTrue = DisabledSurfaceColorConfiguration() public var isFalse = DisabledSurfaceColorConfiguration() public func getColor(_ viewModel: ModelType) -> UIColor { return viewModel.userTrueColor ? isTrue.getColor(viewModel) : isFalse.getColor(viewModel) } }