class RightOwner < InvoicingRecord
  belongs_to :country, optional: true
  belongs_to :vat, class_name: 'ClientVat', optional: true
  belongs_to :right_owner_type, optional: true
  belongs_to :provider, optional: true
  belongs_to :withholding_tax, optional: true
  belongs_to :language, optional: true
  belongs_to :currency, optional: true
  has_many :images
  has_many :statements

  validates :last_name, :address, :zip_code, :city, :email, :country_id, :vat_id, :france_rate, :foreign_rate,
            :right_owner_type_id, :language_id, presence: true

  def paid
    statements.where(status: :done).sum(:total)
  end

  def unpaid
    statements.where(status: :ready).sum(:total)
  end

  def full_name
    [first_name, last_name].compact.join(' ')
  end
end
