class Commission < ApplicationRecord
  self.primary_key = 'commission_id'

  # primary key - need to be unique
  before_create :generate_custom_id

  belongs_to :menu_item, foreign_key: 'product_code'
  has_many :commissioners
  has_many :product_commissions

  # validations
  validates_presence_of :name, :commission_type, :amount
  scope :active, -> {where(is_active: true)}
  private
  def generate_custom_id
    self.commission_id = SeedGenerator.generate_id(self.class.name, "COM")
  end
end
