class ProfilePolicy
  attr_reader :user, :model

  def initialize(user, model)
    @user = user || User.new
    @profile = model
  end

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

    def resolve
      if user.admin?
        scope.all
      else
        scope.all
      end
    end

    private

    attr_reader :user, :scope
  end

  def index?
    @user.admin? || true
  end

  def show?
    @user.admin? || true
  end

  def new?
    @user.signed_in?
  end

  def create?
    @user.signed_in?
  end

  def edit?
    update?
  end

  def update?
    @user.admin? || @user == @profile.user
  end

  def destroy?
    @user.admin? || @user == @profile.user
  end
end
