//
//  FormFieldEffectProtocol.swift
//  MVMCoreUI
//
//  Created by Matt Bruce on 12/6/21.
//  Copyright © 2021 Verizon Wireless. All rights reserved.
//

import Foundation

public protocol FormFieldEffectProtocol: ModelProtocol, RulesContainerProtocol {
    
    /// This is the key to the form field that will take the effect
    var fieldKey: String { get }
  
    /// This is an array of ruleIds that are a property of RulesProtocol for the array of Validation rules within the FormGroupRule.rules
    /// When this effect "rules" are valid (true), the Form will add the fieldKey to the corresponding Validation rule "fields" property.
    /// When this effect "rules" are invalid (false), the Form will remove the fieldKey from the corresponding Validation rule "fields" property.
    var activatedRuleIds: [String]? { get }
    
    /// This function will execute the effect on the field passed in based on the validity. validity is the result of the array of rules run.
    /// - Parameters:
    ///   - validity: This is run against the FormFieldAffect
    ///   - field: Form Field that is bound to the fieldKey
    ///   - form: Form that the formGroup is attached
    ///   - group: FormGroupRule that is attached to this effect
    func setEffect(validity: Bool, field: FormFieldProtocol, form: FormValidator, group: FormGroupRule)
}

public extension FormFieldEffectProtocol {
    var type: String { Self.identifier }
    static var categoryCodingKey: String { "type" }
    static var categoryName: String { "\(FormFieldEffectProtocol.self)" }
}
