class Overlay < ApplicationRecord belongs_to :user, optional: true has_many :template_overlays, dependent: :destroy has_many :server_templates, through: :template_overlays validates :name, :overlay_type, :path, presence: true validates :overlay_type, inclusion: { in: %w[system custom] } validates :name, uniqueness: { scope: :user_id, message: "must be unique per user" } scope :system_overlays, -> { where(overlay_type: "system").where(user_id: nil) } scope :custom_overlays, -> { where(overlay_type: "custom") } scope :for_user, ->(user) { where("user_id IS NULL OR user_id = ?", user.id) } end