VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "IteratorRule"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Public row_ As Long
Private data_ As Excel.Worksheet

Public Sub Init(target As Excel.Worksheet, Optional tRow& = FIRST_DATA_ROW)
  Set data_ = target
  row_ = tRow
End Sub

Public Function Increment(Optional inc& = 1)
  If row_ + inc > 0 Then _
    row_ = row_ + inc
End Function

Public Function GoFirst()
  row_ = FIRST_DATA_ROW
End Function

Public Function GoLast()
  row_ = data_.Columns(S_R_ID).Find(vbNullString, LookAt:=xlWhole).Row - 1
End Function

Public Function GoToID(sID$) As Boolean
  Dim rFound As Excel.Range: Set rFound = data_.Columns(S_R_ID).Find(sID, LookAt:=xlWhole)
  If rFound Is Nothing Then
    GoToID = False
  Else
    GoToID = True
    row_ = rFound.Row
  End If
End Function

Public Function IsDone() As Boolean
  IsDone = data_.Cells(row_, S_R_ID) = vbNullString
End Function

Public Function RemoveRow()
  Call data_.Rows(row_).Delete
End Function

'===== Propertiy Get =====
Public Property Get RuleID() As String
  RuleID = data_.Cells(row_, S_R_ID)
End Property

Public Property Get RuleName() As String
  RuleName = data_.Cells(row_, S_R_NAME)
End Property

Public Property Get Enabled() As Boolean
  Enabled = data_.Cells(row_, S_R_ENABLED) = FLAG_VALUE_ON
End Property

Public Property Get ApplyFixes() As Boolean
  ApplyFixes = data_.Cells(row_, S_R_APPLY) = FLAG_VALUE_ON
End Property

Public Property Get GroupName() As String
  GroupName = data_.Cells(row_, S_R_GROUP)
End Property

Public Property Get Description() As String
  Description = data_.Cells(row_, S_R_DESCRIPTION)
End Property

Public Property Get ErrorsCount() As Long
  ErrorsCount = data_.Cells(row_, S_R_ERRORS)
End Property

Public Property Get FixesCount() As Long
  FixesCount = data_.Cells(row_, S_R_FIXES)
End Property

Public Property Get TimeSpent() As Double
  TimeSpent = data_.Cells(row_, S_R_TIME)
End Property

Public Property Get DescriptionLabel() As String
  DescriptionLabel = Fmt("{1}: {2}", RuleID, RuleName)
End Property

' ==== Property Let ====
Public Property Let RuleID(newVal$)
  data_.Cells(row_, S_R_ID) = newVal
End Property

Public Property Let RuleName(newVal$)
  data_.Cells(row_, S_R_NAME) = newVal
End Property

Public Property Let Enabled(newVal As Boolean)
  data_.Cells(row_, S_R_ENABLED) = IIf(newVal, FLAG_VALUE_ON, FLAG_VALUE_OFF)
End Property

Public Property Let ApplyFixes(newVal As Boolean)
  data_.Cells(row_, S_R_APPLY) = IIf(newVal, FLAG_VALUE_ON, FLAG_VALUE_OFF)
End Property

Public Property Let GroupName(newVal$)
  data_.Cells(row_, S_R_GROUP) = newVal
End Property

Public Property Let Description(newVal$)
  data_.Cells(row_, S_R_DESCRIPTION) = newVal
End Property

Public Property Let ErrorsCount(newVal&)
  data_.Cells(row_, S_R_ERRORS) = newVal
End Property

Public Property Let FixesCount(newVal&)
  data_.Cells(row_, S_R_FIXES) = newVal
End Property

Public Property Let TimeSpent(newVal As Double)
  data_.Cells(row_, S_R_TIME) = newVal
End Property
