class Accounting::PaymentDetail < ApplicationRecord
  enum payment: [:cash, :check, :payjunction_ach, :payjunction_credit_card, :paya_credit_card]

  belongs_to :accounting_transaction, foreign_key: :transaction_id,
    class_name: 'Accounting::Transaction'

  private
    def deleteable?
      return if accounting_transaction.force_delete

      if [:payjunction_ach, :payjunction_credit_card].include?(payment.to_sym)
        errors.add(:base, 'Cannot delete PayJunction payment.')
        throw(:abort)
      end
    end
end
