module Youtube
  class OauthUrl
    AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth".freeze
    SCOPES = [
      "https://www.googleapis.com/auth/youtube",
      "https://www.googleapis.com/auth/youtube.force-ssl"
    ].join(" ").freeze

    def self.build(state:, redirect_uri: ENV["YOUTUBE_REDIRECT_URI"])
      params = {
        client_id: ENV.fetch("YOUTUBE_CLIENT_ID", "not_configured"),
        redirect_uri: redirect_uri,
        response_type: "code",
        scope: SCOPES,
        access_type: "offline",
        prompt: "consent",
        state: state
      }
      "#{AUTH_URL}?#{URI.encode_www_form(params)}"
    end
  end
end
