class School::Google::OauthTokensController < ApplicationController
  def show
    if oauth_token.valid_token?(params[:scopes])
      render_success :ok, json: { scope: oauth_token.scope }
    else
      render_error :unprocessable_entity
    end
  end

  def update
    oauth_token.generate_oauth_token(params[:authorization_code])

    if oauth_token.save
      render_success :ok
    else
      render_error :unprocessable_entity, errors: oauth_token
    end
  end

  def destroy
    if oauth_token.destroy
      render_success :ok
    else
      render_error :unprocessable_entity, errors: oauth_token
    end
  end

  private
    def oauth_token
      @oauth_token ||= current_user.find_or_build_google_oauth_token
    end
end
