class ProjectPolicy
  attr_reader :user, :project

  def initialize(user, project)
    @user = user || User.new
    @project = project
  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?
    true
  end

  def show?
    true
  end

  def create?
    @user.admin? || @user.signed_in?
  end

  def new?
    @user.signed_in?
  end

  def edit?
   @user.admin? || @user == @project.user
  end

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

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

end
