//
//  RuleAnyRequiredModel.swift
//  MVMCoreUI
//
//  Created by Kevin Christiano on 3/13/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

import UIKit

public class RuleAnyRequiredModel: RuleAnyModelProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------

    public static var identifier: String = "anyRequired"
    public var type: String = RuleRequiredModel.identifier
    public var ruleId: String? 
    public var fields: [String]
    public var errorMessage: [String: String]?
    
    //--------------------------------------------------
    // MARK: - Initializer
    //--------------------------------------------------

    public init(fields: [String]) {
        self.fields = fields
    }

    //--------------------------------------------------
    // MARK: - Methods
    //--------------------------------------------------
    
    public func isValid(_ formField: FormFieldProtocol) -> Bool {
        guard let value = formField.formFieldValue() else { return false }
        
        if let valueString = value as? String {
            return valueString.count > 0
            
        } else if let valueBool = value as? Bool {
            return valueBool
        }
        
        return false
    }
    
}
