/*
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"
)


// FullTextSearchAPIService FullTextSearchAPI service
type FullTextSearchAPIService service

type ApiV1FullTextGetRequest struct {
	ctx context.Context
	ApiService *FullTextSearchAPIService
	formType *string
	fillingDateStart *string
	fillingDateEnd *string
	textContains *string
	textNotContain *string
	pageSize *int32
	pageNumber *int32
	sortBy *string
	sortOrder *string
}

// Filter by form type (e.g., \&quot;10-K\&quot;, \&quot;8-K\&quot;). Multiple values can be comma-separated
func (r ApiV1FullTextGetRequest) FormType(formType string) ApiV1FullTextGetRequest {
	r.formType = &formType
	return r
}

// Filter by filling date start (inclusive), format YYYY-MM-DD
func (r ApiV1FullTextGetRequest) FillingDateStart(fillingDateStart string) ApiV1FullTextGetRequest {
	r.fillingDateStart = &fillingDateStart
	return r
}

// Filter by filling date end (inclusive), format YYYY-MM-DD
func (r ApiV1FullTextGetRequest) FillingDateEnd(fillingDateEnd string) ApiV1FullTextGetRequest {
	r.fillingDateEnd = &fillingDateEnd
	return r
}

// Keywords that the text must contain. Multiple values can be comma-separated
func (r ApiV1FullTextGetRequest) TextContains(textContains string) ApiV1FullTextGetRequest {
	r.textContains = &textContains
	return r
}

// Keywords that the text must not contain. Multiple values can be comma-separated
func (r ApiV1FullTextGetRequest) TextNotContain(textNotContain string) ApiV1FullTextGetRequest {
	r.textNotContain = &textNotContain
	return r
}

// Number of results per page (default: 100)
func (r ApiV1FullTextGetRequest) PageSize(pageSize int32) ApiV1FullTextGetRequest {
	r.pageSize = &pageSize
	return r
}

// Page number to retrieve (default: 1)
func (r ApiV1FullTextGetRequest) PageNumber(pageNumber int32) ApiV1FullTextGetRequest {
	r.pageNumber = &pageNumber
	return r
}

// Field to sort by (default: AccessionNumber)
func (r ApiV1FullTextGetRequest) SortBy(sortBy string) ApiV1FullTextGetRequest {
	r.sortBy = &sortBy
	return r
}

// Sort order (asc or desc). Defaults to asc
func (r ApiV1FullTextGetRequest) SortOrder(sortOrder string) ApiV1FullTextGetRequest {
	r.sortOrder = &sortOrder
	return r
}

func (r ApiV1FullTextGetRequest) Execute() ([]DTOSecFilingResultDto, *http.Response, error) {
	return r.ApiService.V1FullTextGetExecute(r)
}

/*
V1FullTextGet Full-text search of SEC filing documents

Search across SEC filing documents with advanced filtering and sorting capabilities.

### Available Sort Fields

Field Name | Description
-----------|-------------
AccessionNumber | SEC filing accession number
FormType | Type of the filing document
FilingDate | Date when filing was submitted
CompanyName | Name of the company
CIK | Central Index Key
DocumentFilename | Name of the filing document
DocumentDescription | Description of the document

### Search Options

Option | Description
--------|-------------
text_contains | Keywords that must appear in the document
text_not_contain | Keywords that must not appear in the document

### Date Format
All dates must be provided in YYYY-MM-DD format

:::tip
Use text_contains and text_not_contain with multiple keywords separated by commas for more precise searches
:::

:::note
The search is case-insensitive and supports partial word matches
:::

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

// Execute executes the request
//  @return []DTOSecFilingResultDto
func (a *FullTextSearchAPIService) V1FullTextGetExecute(r ApiV1FullTextGetRequest) ([]DTOSecFilingResultDto, *http.Response, error) {
	var (
		localVarHTTPMethod   = http.MethodGet
		localVarPostBody     interface{}
		formFiles            []formFile
		localVarReturnValue  []DTOSecFilingResultDto
	)

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

	localVarPath := localBasePath + "/v1/full-text"

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

	if r.formType != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "form_type", r.formType, "form", "")
	}
	if r.fillingDateStart != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "filling_date_start", r.fillingDateStart, "form", "")
	}
	if r.fillingDateEnd != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "filling_date_end", r.fillingDateEnd, "form", "")
	}
	if r.textContains != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "text_contains", r.textContains, "form", "")
	}
	if r.textNotContain != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "text_not_contain", r.textNotContain, "form", "")
	}
	if r.pageSize != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "page_size", r.pageSize, "form", "")
	}
	if r.pageNumber != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "page_number", r.pageNumber, "form", "")
	}
	if r.sortBy != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "sort_by", r.sortBy, "form", "")
	} else {
		var defaultValue string = "AccessionNumber"
		r.sortBy = &defaultValue
	}
	if r.sortOrder != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "sort_order", r.sortOrder, "form", "")
	} else {
		var defaultValue string = "asc"
		r.sortOrder = &defaultValue
	}
	// 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
}
