# app/policies/application_policy.rb
class ApplicationPolicy
  attr_reader :user, :record

  def initialize(user, record)
    @user   = user
    @record = record
  end

  def index?   = user.pode_consolidar? || user.admin?
  def show?    = user.pode_consolidar? || user.admin?
  def create?  = user.pode_consolidar? || user.admin?
  def new?     = create?
  def update?  = user.pode_consolidar? || user.admin?
  def edit?    = update?
  def destroy? = user.admin?

  # Helpers de papel disponíveis para todas as policies (delegam para o User)
  def admin?
    user.admin?
  end

  def admin_ou_gerente?
    user.admin? || user.gerente?
  end

  class Scope
    def initialize(user, scope)
      @user  = user
      @scope = scope
    end

    def resolve
      @scope.all
    end

    private

    attr_reader :user, :scope
  end
end
