//
//  FormFieldRuleRequiredModel.swift
//  MVMCoreUI
//
//  Created by Suresh, Kamlesh on 2/24/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

import Foundation


public class RuleRequiredModel: RulesProtocol {
    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    public static var identifier: String = "allRequired"
    public var type: String = RuleRequiredModel.identifier
    public var ruleId: String?
    public var errorMessage: [String: String]?
    public var fields: [String]

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