// Code generated by go-swagger; DO NOT EDIT.

package app

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

import (
	"context"
	"net/http"
	"time"

	"github.com/go-openapi/errors"
	"github.com/go-openapi/runtime"
	cr "github.com/go-openapi/runtime/client"
	"github.com/go-openapi/strfmt"
	"github.com/go-openapi/swag"
)

// NewListAppsParams creates a new ListAppsParams object,
// with the default timeout for this client.
//
// Default values are not hydrated, since defaults are normally applied by the API server side.
//
// To enforce default values in parameter, use SetDefaults or WithDefaults.
func NewListAppsParams() *ListAppsParams {
	return &ListAppsParams{
		timeout: cr.DefaultTimeout,
	}
}

// NewListAppsParamsWithTimeout creates a new ListAppsParams object
// with the ability to set a timeout on a request.
func NewListAppsParamsWithTimeout(timeout time.Duration) *ListAppsParams {
	return &ListAppsParams{
		timeout: timeout,
	}
}

// NewListAppsParamsWithContext creates a new ListAppsParams object
// with the ability to set a context for a request.
func NewListAppsParamsWithContext(ctx context.Context) *ListAppsParams {
	return &ListAppsParams{
		Context: ctx,
	}
}

// NewListAppsParamsWithHTTPClient creates a new ListAppsParams object
// with the ability to set a custom HTTPClient for a request.
func NewListAppsParamsWithHTTPClient(client *http.Client) *ListAppsParams {
	return &ListAppsParams{
		HTTPClient: client,
	}
}

/*
ListAppsParams contains all the parameters to send to the API endpoint

	for the list apps operation.

	Typically these are written to a http.Request.
*/
type ListAppsParams struct {

	/* Page.

	   The current page of the pagination

	   Format: int32
	*/
	Page *int32

	/* Query.

	   The search query
	*/
	Query *string

	/* Size.

	   The page size of the pagination

	   Format: int32
	*/
	Size *int32

	/* SortColumn.

	   The column ID to sort by
	*/
	SortColumn *string

	/* SortDesc.

	   Whether to sort in descending order (true) or ascending order (false)
	*/
	SortDesc *bool

	/* Types.

	    The app type filter

	- APP_TYPE_UNSPECIFIED: Unspecified Envelope Type.
	- APP_TYPE_AGENT_A2A: Agent A2A App Type.
	- APP_TYPE_AGENT_OASF: Agent OASF App Type.
	- APP_TYPE_MCP_SERVER: Agent MCP Server App Type.
	*/
	Types []string

	timeout    time.Duration
	Context    context.Context
	HTTPClient *http.Client
}

// WithDefaults hydrates default values in the list apps params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *ListAppsParams) WithDefaults() *ListAppsParams {
	o.SetDefaults()
	return o
}

// SetDefaults hydrates default values in the list apps params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *ListAppsParams) SetDefaults() {
	// no default values defined for this parameter
}

// WithTimeout adds the timeout to the list apps params
func (o *ListAppsParams) WithTimeout(timeout time.Duration) *ListAppsParams {
	o.SetTimeout(timeout)
	return o
}

// SetTimeout adds the timeout to the list apps params
func (o *ListAppsParams) SetTimeout(timeout time.Duration) {
	o.timeout = timeout
}

// WithContext adds the context to the list apps params
func (o *ListAppsParams) WithContext(ctx context.Context) *ListAppsParams {
	o.SetContext(ctx)
	return o
}

// SetContext adds the context to the list apps params
func (o *ListAppsParams) SetContext(ctx context.Context) {
	o.Context = ctx
}

// WithHTTPClient adds the HTTPClient to the list apps params
func (o *ListAppsParams) WithHTTPClient(client *http.Client) *ListAppsParams {
	o.SetHTTPClient(client)
	return o
}

// SetHTTPClient adds the HTTPClient to the list apps params
func (o *ListAppsParams) SetHTTPClient(client *http.Client) {
	o.HTTPClient = client
}

// WithPage adds the page to the list apps params
func (o *ListAppsParams) WithPage(page *int32) *ListAppsParams {
	o.SetPage(page)
	return o
}

// SetPage adds the page to the list apps params
func (o *ListAppsParams) SetPage(page *int32) {
	o.Page = page
}

// WithQuery adds the query to the list apps params
func (o *ListAppsParams) WithQuery(query *string) *ListAppsParams {
	o.SetQuery(query)
	return o
}

// SetQuery adds the query to the list apps params
func (o *ListAppsParams) SetQuery(query *string) {
	o.Query = query
}

// WithSize adds the size to the list apps params
func (o *ListAppsParams) WithSize(size *int32) *ListAppsParams {
	o.SetSize(size)
	return o
}

// SetSize adds the size to the list apps params
func (o *ListAppsParams) SetSize(size *int32) {
	o.Size = size
}

// WithSortColumn adds the sortColumn to the list apps params
func (o *ListAppsParams) WithSortColumn(sortColumn *string) *ListAppsParams {
	o.SetSortColumn(sortColumn)
	return o
}

// SetSortColumn adds the sortColumn to the list apps params
func (o *ListAppsParams) SetSortColumn(sortColumn *string) {
	o.SortColumn = sortColumn
}

// WithSortDesc adds the sortDesc to the list apps params
func (o *ListAppsParams) WithSortDesc(sortDesc *bool) *ListAppsParams {
	o.SetSortDesc(sortDesc)
	return o
}

// SetSortDesc adds the sortDesc to the list apps params
func (o *ListAppsParams) SetSortDesc(sortDesc *bool) {
	o.SortDesc = sortDesc
}

// WithTypes adds the types to the list apps params
func (o *ListAppsParams) WithTypes(types []string) *ListAppsParams {
	o.SetTypes(types)
	return o
}

// SetTypes adds the types to the list apps params
func (o *ListAppsParams) SetTypes(types []string) {
	o.Types = types
}

// WriteToRequest writes these params to a swagger request
func (o *ListAppsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {

	if err := r.SetTimeout(o.timeout); err != nil {
		return err
	}
	var res []error

	if o.Page != nil {

		// query param page
		var qrPage int32

		if o.Page != nil {
			qrPage = *o.Page
		}
		qPage := swag.FormatInt32(qrPage)
		if qPage != "" {

			if err := r.SetQueryParam("page", qPage); err != nil {
				return err
			}
		}
	}

	if o.Query != nil {

		// query param query
		var qrQuery string

		if o.Query != nil {
			qrQuery = *o.Query
		}
		qQuery := qrQuery
		if qQuery != "" {

			if err := r.SetQueryParam("query", qQuery); err != nil {
				return err
			}
		}
	}

	if o.Size != nil {

		// query param size
		var qrSize int32

		if o.Size != nil {
			qrSize = *o.Size
		}
		qSize := swag.FormatInt32(qrSize)
		if qSize != "" {

			if err := r.SetQueryParam("size", qSize); err != nil {
				return err
			}
		}
	}

	if o.SortColumn != nil {

		// query param sortColumn
		var qrSortColumn string

		if o.SortColumn != nil {
			qrSortColumn = *o.SortColumn
		}
		qSortColumn := qrSortColumn
		if qSortColumn != "" {

			if err := r.SetQueryParam("sortColumn", qSortColumn); err != nil {
				return err
			}
		}
	}

	if o.SortDesc != nil {

		// query param sortDesc
		var qrSortDesc bool

		if o.SortDesc != nil {
			qrSortDesc = *o.SortDesc
		}
		qSortDesc := swag.FormatBool(qrSortDesc)
		if qSortDesc != "" {

			if err := r.SetQueryParam("sortDesc", qSortDesc); err != nil {
				return err
			}
		}
	}

	if o.Types != nil {

		// binding items for types
		joinedTypes := o.bindParamTypes(reg)

		// query array param types
		if err := r.SetQueryParam("types", joinedTypes...); err != nil {
			return err
		}
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

// bindParamListApps binds the parameter types
func (o *ListAppsParams) bindParamTypes(formats strfmt.Registry) []string {
	typesIR := o.Types

	var typesIC []string
	for _, typesIIR := range typesIR { // explode []string

		typesIIV := typesIIR // string as string
		typesIC = append(typesIC, typesIIV)
	}

	// items.CollectionFormat: "multi"
	typesIS := swag.JoinByFormat(typesIC, "multi")

	return typesIS
}
