class FinancialAidContact < ApplicationRecord
  audited

  belongs_to :application, class_name: :FinancialAidApplication
  belongs_to :contact

  has_many :connection_logs, class_name: '::ConnectionLog', as: :associated, dependent: :destroy

  before_save :set_reported_at, if: :credit_report_key_changed?

  after_save :submit_application, if: :credit_report_key?

  private
    def submit_application
      return if !application.application_contacts.all?(&:credit_report_key?)

      application.update!(status: :submitted)
    end

    def set_reported_at
      self.reported_at = Time.zone.now if credit_report_key?
    end
end
