require_relative 'apply_year'
require_relative 'apply_month'

class ApplyDate
  def self.validate(row, repo)
    reasons = []

    reasons << validate_apply_period(row, repo)

    reasons << ApplyYear.validate(row)
    reasons << ApplyMonth.validate(row)
    reasons
  end

  def self.validate_apply_period(row, repo)
    reasons = []

    period_id = repo.get_period_id(row[:apply_month], row[:apply_year])
    period_is_open = repo.check_period_is_open(period_id)

    unless period_id && period_is_open
      reasons << 'Apply period is either missing in Abacus or already closed'
    end

    reasons
  end
end
