// // SelectorGroupModel.swift // VDS // // Created by Matt Bruce on 8/11/22. // import Foundation ///MARK: Groups that allow anything selected public protocol SelectorGroupModelable: Modelable, FormFieldable { associatedtype SelectorModelType: Modelable where SelectorModelType: FormFieldable & Selectable var selectors: [SelectorModelType] { get set } } extension SelectorGroupModelable { public var debugDescription: String { "group id: \(id.uuidString)\r\(selectors.compactMap{"id: \($0.debugDescription) \($0.selected ? "*" : "")"}.joined(separator: "\r"))" } } ///MARK: Groups that allow single selections public protocol SelectorGroupSelectedModelable: SelectorGroupModelable { var selectedModel: SelectorModelType? { get } } extension SelectorGroupSelectedModelable { public var selectedModel: SelectorModelType? { if let index = selectors.firstIndex(where: { element in return element.selected == true }) { return selectors[index] } else { return nil } } }