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

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

    //--------------------------------------------------
    // MARK: - Properties
    //--------------------------------------------------
    
    public func isValid(_ formField: FormFieldProtocol) -> Bool {
        
        if let stringToValidate = formField.formFieldValue() as? String {
            return MVMCoreUIUtility.validate(stringToValidate, withRegularExpression: regex)
        }
        
        return false
    }
    
}
