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(team_id:, 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: team_id
      }
      "#{AUTH_URL}?#{URI.encode_www_form(params)}"
    end
  end
end
