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

package credit_management

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

import (
	"net/http"

	"github.com/go-openapi/errors"
	"github.com/go-openapi/runtime"
	"github.com/go-openapi/runtime/middleware"
	"github.com/go-openapi/strfmt"
	"github.com/go-openapi/swag"
	"github.com/go-openapi/validate"
)

// NewGetHistoryParams creates a new GetHistoryParams object
// no default values defined in spec.
func NewGetHistoryParams() GetHistoryParams {

	return GetHistoryParams{}
}

// GetHistoryParams contains all the bound params for the get history operation
// typically these are obtained from a http.Request
//
// swagger:parameters getHistory
type GetHistoryParams struct {

	// HTTP Request Object
	HTTPRequest *http.Request `json:"-"`

	/*Boolean variable to control if the system consumptions have to be listed or not
	  In: query
	*/
	FilterSystem *bool
	/*Id of the account to get the history
	  Required: true
	  In: path
	*/
	ID string
	/*Medium (cash/credit) to be used as filter
	  In: query
	*/
	Medium *string
}

// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
// for simple values it will use straight method calls.
//
// To ensure default values, the struct must have been initialized with NewGetHistoryParams() beforehand.
func (o *GetHistoryParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
	var res []error

	o.HTTPRequest = r

	qs := runtime.Values(r.URL.Query())

	qFilterSystem, qhkFilterSystem, _ := qs.GetOK("filterSystem")
	if err := o.bindFilterSystem(qFilterSystem, qhkFilterSystem, route.Formats); err != nil {
		res = append(res, err)
	}

	rID, rhkID, _ := route.Params.GetOK("id")
	if err := o.bindID(rID, rhkID, route.Formats); err != nil {
		res = append(res, err)
	}

	qMedium, qhkMedium, _ := qs.GetOK("medium")
	if err := o.bindMedium(qMedium, qhkMedium, route.Formats); err != nil {
		res = append(res, err)
	}

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

// bindFilterSystem binds and validates parameter FilterSystem from query.
func (o *GetHistoryParams) bindFilterSystem(rawData []string, hasKey bool, formats strfmt.Registry) error {
	var raw string
	if len(rawData) > 0 {
		raw = rawData[len(rawData)-1]
	}

	// Required: false
	// AllowEmptyValue: false
	if raw == "" { // empty values pass all other validations
		return nil
	}

	value, err := swag.ConvertBool(raw)
	if err != nil {
		return errors.InvalidType("filterSystem", "query", "bool", raw)
	}
	o.FilterSystem = &value

	return nil
}

// bindID binds and validates parameter ID from path.
func (o *GetHistoryParams) bindID(rawData []string, hasKey bool, formats strfmt.Registry) error {
	var raw string
	if len(rawData) > 0 {
		raw = rawData[len(rawData)-1]
	}

	// Required: true
	// Parameter is provided by construction from the route

	o.ID = raw

	return nil
}

// bindMedium binds and validates parameter Medium from query.
func (o *GetHistoryParams) bindMedium(rawData []string, hasKey bool, formats strfmt.Registry) error {
	var raw string
	if len(rawData) > 0 {
		raw = rawData[len(rawData)-1]
	}

	// Required: false
	// AllowEmptyValue: false
	if raw == "" { // empty values pass all other validations
		return nil
	}

	o.Medium = &raw

	if err := o.validateMedium(formats); err != nil {
		return err
	}

	return nil
}

// validateMedium carries on validations for parameter Medium
func (o *GetHistoryParams) validateMedium(formats strfmt.Registry) error {

	if err := validate.EnumCase("medium", "query", *o.Medium, []interface{}{"credit", "cash"}, true); err != nil {
		return err
	}

	return nil
}
