class AccountPaymentConfig < ApplicationRecord
  include Base::AccountPaymentConfig
  include Encryptable

  enum processor: { payjunction: 7 }
  enum environment: { production: 0, sandbox: 1 }

  belongs_to :school, foreign_key: :SchoolID, inverse_of: :payjunction_config

  before_save :reset_environment, if: -> { production? && school.internal? }

  def decrypted_password
    legacy_decrypt(password)
  end

  private
    def reset_environment
      self.environment = :production
    end
end
