"""
    HCL AppScan on Cloud (v2)

    This API allows you to interact with the service. The API allows you to perform many of the operations available in the UI and more.</br>For authentication, use the relevant APIs in the Account section. A successful authentication response includes a bearer token for use in subsequent API calls. Pasting this token in the 'Access token' field above will automatically add the authorization header to any API call that requires a valid session.

    OpenAPI spec version: v2

    Generated by: https://github.com/swagger-api/swagger-codegen.git
"""

import re  # noqa: F401

# python 2 and python 3 compatibility library
from pyasoc.api_client import ApiClient
from pyasoc.models import UserSiteCommonModelsUploadViewModel


class FileUploadApi:
    """NOTE: This class is auto generated by the swagger code generator program.

    Do not edit the class manually.
    Ref: https://github.com/swagger-api/swagger-codegen
    """

    def __init__(self, api_client=None):
        if api_client is None:
            api_client = ApiClient()
        self.api_client = api_client

    def file_upload_upload(self, file_to_upload, **kwargs):
        """Upload file

        Upload a file to use in actions that require files (such as Create Scan and Execute Scan).<br />              Supported file formats: APK, CONFIG, CSV, IPA, IRX, SCAN, SCANT, JSON and ZIP.<br />              If ZIP or Json file is uploaded, 'fileType' parameter is required and the file must contain the appropriate content.<br />              Returns an ID for use as input for the other actions.<br />              Includes file format validation.<br />              The expected Content-Type of the request is multipart/form-data. The request should contain a single file parameter named \"fileToUpload\".<br />              The uploaded file will be available for use for 30 minutes. After this period, the file will be deleted from the server
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.file_upload_upload(file_to_upload, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param file file_to_upload: (required)
        :param str file_type: Uploaded File type (required for zip and postman collection json files only)
        :param str file_name: If provided, this parameter will override the name of the uploaded file, including its extension (APK, CONFIG, CSV, IPA, IRX, SCAN and SCANT).
        :return: UserSiteCommonModelsUploadViewModel
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs["_return_http_data_only"] = True
        if kwargs.get("async_req"):
            return self.file_upload_upload_with_http_info(file_to_upload, **kwargs)
        else:
            (data) = self.file_upload_upload_with_http_info(file_to_upload, **kwargs)
            return data

    def file_upload_upload_with_http_info(
        self, file_to_upload, **kwargs
    ) -> UserSiteCommonModelsUploadViewModel:
        """Upload file

        Upload a file to use in actions that require files (such as Create Scan and Execute Scan).<br />              Supported file formats: APK, CONFIG, CSV, IPA, IRX, SCAN, SCANT, JSON and ZIP.<br />              If ZIP or Json file is uploaded, 'fileType' parameter is required and the file must contain the appropriate content.<br />              Returns an ID for use as input for the other actions.<br />              Includes file format validation.<br />              The expected Content-Type of the request is multipart/form-data. The request should contain a single file parameter named \"fileToUpload\".<br />              The uploaded file will be available for use for 30 minutes. After this period, the file will be deleted from the server
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.file_upload_upload_with_http_info(file_to_upload, async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param file file_to_upload: (required)
        :param str file_type: Uploaded File type (required for zip and postman collection json files only)
        :param str file_name: If provided, this parameter will override the name of the uploaded file, including its extension (APK, CONFIG, CSV, IPA, IRX, SCAN and SCANT).
        :return: UserSiteCommonModelsUploadViewModel
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ["file_to_upload", "file_type", "file_name"]
        all_params.append("async_req")
        all_params.append("_return_http_data_only")
        all_params.append("_preload_content")
        all_params.append("_request_timeout")

        params = locals()
        for key, val in params["kwargs"].items():
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'" " to method file_upload_upload" % key
                )
            params[key] = val
        del params["kwargs"]
        # verify the required parameter 'file_to_upload' is set
        if self.api_client.client_side_validation and (
            "file_to_upload" not in params or params["file_to_upload"] is None
        ):
            raise ValueError(
                "Missing the required parameter `file_to_upload` when calling `file_upload_upload`"
            )

        if self.api_client.client_side_validation and (
            "file_name" in params and len(params["file_name"]) > 2048
        ):
            raise ValueError(
                "Invalid value for parameter `file_name` when calling `file_upload_upload`, length must be less than or equal to `2048`"
            )
        collection_formats = {}

        path_params = {}

        query_params = []
        if "file_type" in params:
            query_params.append(("fileType", params["file_type"]))

        header_params = {}

        form_params = []
        local_var_files = {}
        if "file_to_upload" in params:
            local_var_files["fileToUpload"] = params["file_to_upload"]
        if "file_name" in params:
            form_params.append(("fileName", params["file_name"]))

        body_params = None
        # HTTP header `Accept`
        header_params["Accept"] = self.api_client.select_header_accept(
            ["application/json", "text/json", "text/csv"]
        )

        # HTTP header `Content-Type`
        header_params["Content-Type"] = self.api_client.select_header_content_type(
            ["multipart/form-data"]
        )

        # Authentication setting
        auth_settings = ["AccessToken"]

        return self.api_client.call_api(
            "/api/v2/FileUpload",
            "POST",
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type="UserSiteCommonModelsUploadViewModel",
            auth_settings=auth_settings,
            async_req=params.get("async_req"),
            _return_http_data_only=params.get("_return_http_data_only"),
            _preload_content=params.get("_preload_content", True),
            _request_timeout=params.get("_request_timeout"),
            collection_formats=collection_formats,
        )
