class BillingInformation < ApplicationRecord
  belongs_to :user
  belongs_to :billing_country, class_name: IptcCountry.name, optional: true

  validates :siret, format: { with: /\A\d{14}\z/, message: I18n.t('siret_error') , allow_blank: true }

  def json
    attributes.slice(*%w[billing_company siret billing_city billing_phone billing_email billing_address billing_zip_code billing_country_id]).delete_if { |_,v| v.blank? }.to_json
  end
end
