/*
FinFeedAPI SEC REST API

No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

API version: v1
Contact: support@apibricks.io
*/

// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.

package openapi

import (
	"bytes"
	"context"
	"io"
	"net/http"
	"net/url"
)


// XBRLConversionAPIService XBRLConversionAPI service
type XBRLConversionAPIService service

type ApiV1XbrlConverterGetRequest struct {
	ctx context.Context
	ApiService *XBRLConversionAPIService
	htmUrl *string
	xbrlUrl *string
	accessionNo *string
}

// URL of the filing ending with .htm or .html
func (r ApiV1XbrlConverterGetRequest) HtmUrl(htmUrl string) ApiV1XbrlConverterGetRequest {
	r.htmUrl = &htmUrl
	return r
}

// URL of the XBRL file ending with .xml
func (r ApiV1XbrlConverterGetRequest) XbrlUrl(xbrlUrl string) ApiV1XbrlConverterGetRequest {
	r.xbrlUrl = &xbrlUrl
	return r
}

// SEC filing accession number
func (r ApiV1XbrlConverterGetRequest) AccessionNo(accessionNo string) ApiV1XbrlConverterGetRequest {
	r.accessionNo = &accessionNo
	return r
}

func (r ApiV1XbrlConverterGetRequest) Execute() (map[string]interface{}, *http.Response, error) {
	return r.ApiService.V1XbrlConverterGetExecute(r)
}

/*
V1XbrlConverterGet Convert XBRL data to JSON format

Converts XBRL data to JSON format using one of three possible input methods.

### Input Methods

1. HTML URL (htm-url)
   - URL of the filing ending with .htm or .html
   - Both filing URLs and index page URLs are accepted
   - Example: https://www.sec.gov/Archives/edgar/data/1318605/000156459021004599/tsla-10k_20201231.htm

2. XBRL URL (xbrl-url)
   - URL of the XBRL file ending with .xml
   - Can be found in the dataFiles array from Query API
   - Example: https://www.sec.gov/Archives/edgar/data/1318605/000156459021004599/tsla-10k_20201231_htm.xml

3. Accession Number (accession-no)
   - The SEC filing accession number
   - Example: 0001564590-21-004599

:::note
Only one of the three parameters should be provided. If multiple parameters are provided, the priority order is:
1. htm-url
2. xbrl-url
3. accession-no
:::

### Supported Filing Types

- Annual Reports (10-K)
- Quarterly Reports (10-Q)
- Current Reports (8-K)
- Registration Statements (S-1, S-3)
- Foreign Private Issuer Reports (20-F, 40-F)

### Response Format

The API returns a JSON object containing:
- Financial statements (Income Statement, Balance Sheet, Cash Flow Statement)
- Accounting policies and footnotes
- Company information
- Filing metadata

### Example Response
```json
{
  "StatementsOfIncome": {
    "RevenueFromContractWithCustomerExcludingAssessedTax": [
      {
        "decimals": "-6",
        "unitRef": "U_USD",
        "period": {
          "startDate": "2023-07-01",
          "endDate": "2024-06-30"
        },
        "value": "245122000000"
      }
    ]
  }
}
```

 @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
 @return ApiV1XbrlConverterGetRequest
*/
func (a *XBRLConversionAPIService) V1XbrlConverterGet(ctx context.Context) ApiV1XbrlConverterGetRequest {
	return ApiV1XbrlConverterGetRequest{
		ApiService: a,
		ctx: ctx,
	}
}

// Execute executes the request
//  @return map[string]interface{}
func (a *XBRLConversionAPIService) V1XbrlConverterGetExecute(r ApiV1XbrlConverterGetRequest) (map[string]interface{}, *http.Response, error) {
	var (
		localVarHTTPMethod   = http.MethodGet
		localVarPostBody     interface{}
		formFiles            []formFile
		localVarReturnValue  map[string]interface{}
	)

	localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "XBRLConversionAPIService.V1XbrlConverterGet")
	if err != nil {
		return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
	}

	localVarPath := localBasePath + "/v1/xbrl-converter"

	localVarHeaderParams := make(map[string]string)
	localVarQueryParams := url.Values{}
	localVarFormParams := url.Values{}

	if r.htmUrl != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "htm-url", r.htmUrl, "form", "")
	}
	if r.xbrlUrl != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "xbrl-url", r.xbrlUrl, "form", "")
	}
	if r.accessionNo != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "accession-no", r.accessionNo, "form", "")
	}
	// to determine the Content-Type header
	localVarHTTPContentTypes := []string{}

	// set Content-Type header
	localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
	if localVarHTTPContentType != "" {
		localVarHeaderParams["Content-Type"] = localVarHTTPContentType
	}

	// to determine the Accept header
	localVarHTTPHeaderAccepts := []string{"application/json"}

	// set Accept header
	localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
	if localVarHTTPHeaderAccept != "" {
		localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
	}
	if r.ctx != nil {
		// API Key Authentication
		if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
			if apiKey, ok := auth["APIKey"]; ok {
				var key string
				if apiKey.Prefix != "" {
					key = apiKey.Prefix + " " + apiKey.Key
				} else {
					key = apiKey.Key
				}
				localVarHeaderParams["Authorization"] = key
			}
		}
	}
	req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
	if err != nil {
		return localVarReturnValue, nil, err
	}

	localVarHTTPResponse, err := a.client.callAPI(req)
	if err != nil || localVarHTTPResponse == nil {
		return localVarReturnValue, localVarHTTPResponse, err
	}

	localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
	localVarHTTPResponse.Body.Close()
	localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
	if err != nil {
		return localVarReturnValue, localVarHTTPResponse, err
	}

	if localVarHTTPResponse.StatusCode >= 300 {
		newErr := &GenericOpenAPIError{
			body:  localVarBody,
			error: localVarHTTPResponse.Status,
		}
		if localVarHTTPResponse.StatusCode == 400 {
			var v MvcValidationProblemDetails
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarReturnValue, localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
			return localVarReturnValue, localVarHTTPResponse, newErr
		}
		if localVarHTTPResponse.StatusCode == 500 {
			var v MvcProblemDetails
			err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
			if err != nil {
				newErr.error = err.Error()
				return localVarReturnValue, localVarHTTPResponse, newErr
			}
					newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
					newErr.model = v
		}
		return localVarReturnValue, localVarHTTPResponse, newErr
	}

	err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
	if err != nil {
		newErr := &GenericOpenAPIError{
			body:  localVarBody,
			error: err.Error(),
		}
		return localVarReturnValue, localVarHTTPResponse, newErr
	}

	return localVarReturnValue, localVarHTTPResponse, nil
}
