class BillingCompany < InvoicingRecord
  belongs_to :vat, class_name: 'ClientVat', foreign_key: :vat_id
  belongs_to :billing_country, class_name: 'Country', foreign_key: :billing_country_id
  belongs_to :payment_type
  has_many :titles, dependent: :nullify
  has_many :users, through: :titles
  has_many :billings

  validates_uniqueness_of :billing_company, allow_blank: true

  def full_address
    [billing_address, billing_zip_code, billing_city].reject(&:blank?).join(' ')
  end

  def conditions
    [
      ("#{time_limit} jours" if time_limit.to_i > 0),
      ("fin de mois" if end_of_month)
    ].compact.join(' ')
  end

  def country_type
    billing_country_id == 74 ? :france : :foreign
  end
end
