/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.appium.java_client.screenrecording;

import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Optional.ofNullable;

import com.google.common.collect.ImmutableMap;

import java.util.Map;

public class ScreenRecordingUploadOptions {
    private String remotePath;
    private String user;
    private String pass;
    private String method;

    public static ScreenRecordingUploadOptions uploadOptions() {
        return new ScreenRecordingUploadOptions();
    }

    /**
     * The path to the remote location, where the resulting video should be uploaded.
     *
     * @param remotePath The path to a writable remote location.
     * @return self instance for chaining.
     */
    public ScreenRecordingUploadOptions withRemotePath(String remotePath) {
        this.remotePath = checkNotNull(remotePath);
        return this;
    }

    /**
     * Sets the credentials for remote ftp/http authentication (if needed).
     * This option only has an effect if remotePath is provided.
     *
     * @param user The name of the user for the remote authentication.
     * @param pass The password for the remote authentication.
     * @return self instance for chaining.
     */
    public ScreenRecordingUploadOptions withAuthCredentials(String user, String pass) {
        this.user = checkNotNull(user);
        this.pass = checkNotNull(pass);
        return this;
    }

    public enum RequestMethod {
        POST, PUT
    }

    /**
     * Sets the method name for http(s) upload. PUT is used by default.
     * This option only has an effect if remotePath is provided.
     *
     * @param method The HTTP method name.
     * @return self instance for chaining.
     */
    public ScreenRecordingUploadOptions withHttpMethod(RequestMethod method) {
        this.method = checkNotNull(method).name();
        return this;
    }

    /**
     * Builds a map, which is ready to be passed to the subordinated
     * Appium API.
     *
     * @return arguments mapping.
     */
    public Map<String, Object> build() {
        final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
        ofNullable(remotePath).map(x -> builder.put("remotePath", x));
        ofNullable(user).map(x -> builder.put("user", x));
        ofNullable(pass).map(x -> builder.put("pass", x));
        ofNullable(method).map(x -> builder.put("method", x));
        return builder.build();
    }
}

@@ -1048,16 +1048,135 @@
  method;
+%0A    private String fileFieldName;%0A    private Map%3CString, String%3E headers;%0A    private Map%3CString, Object%3E formFields;
 %0A%0A    pu
@@ -2655,32 +2655,1366 @@
 rn this;%0A    %7D%0A%0A
+    /**%0A     * Sets the form field name containing the binary payload in multipart/form-data%0A     * requests.%0A     *%0A     * @since Appium 1.18.0%0A     * @param fileFieldName The name of the form field containing the binary payload.%0A     *                      %22file%22 by default.%0A     * @return self instance for chaining.%0A     */%0A    public ScreenRecordingUploadOptions withFileFieldName(String fileFieldName) %7B%0A        this.fileFieldName = checkNotNull(fileFieldName);%0A        return this;%0A    %7D%0A%0A    /**%0A     * Sets additional form fields in multipart/form-data requests.%0A     *%0A     * @since Appium 1.18.0%0A     * @param formFields form fields mapping. If any entry has the same key as%0A     *                   %60fileFieldName%60 then it is going to be ignored.%0A     * @return self instance for chaining.%0A     */%0A    public ScreenRecordingUploadOptions withFormFields(Map%3CString, Object%3E formFields) %7B%0A        this.formFields = checkNotNull(formFields);%0A        return this;%0A    %7D%0A%0A    /**%0A     * Sets additional headers in multipart/form-data requests.%0A     *%0A     * @since Appium 1.18.0%0A     * @param headers headers mapping.%0A     * @return self instance for chaining.%0A     */%0A    public ScreenRecordingUploadOptions withHeaders(Map%3CString, String%3E headers) %7B%0A        this.headers = checkNotNull(headers);%0A        return this;%0A    %7D%0A%0A
     /**%0A     * B
@@ -4449,32 +4449,32 @@
 ut(%22pass%22, x));%0A
-
         ofNullab
@@ -4512,32 +4512,245 @@
 (%22method%22, x));%0A
+        ofNullable(fileFieldName).map(x -%3E builder.put(%22fileFieldName%22, x));%0A        ofNullable(formFields).map(x -%3E builder.put(%22formFields%22, x));%0A        ofNullable(headers).map(x -%3E builder.put(%22headers%22, x));%0A
         return b

Add new upload options that were introduced recently (#1342)