class Service::Group < ApplicationRecord
  include Base::Service::Group
  include Cacheable

  audited

  associations_for legacy: true do |a|
    a.belongs_to :school
  end

  has_many :opportunities, foreign_key: :SOGID, dependent: :restrict_with_error, inverse_of: :group,
    class_name: 'Service::Opportunity'

  validates :name, presence: true, length: { maximum: 16 }
  validates :description, length: { maximum: 64 }

  private
    def set_cache_keys
      self.cache_keys = ["school/#{school_id}/service_groups"]
    end
end
