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

package metadata

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

import (
	"context"
	"net/http"
	"strconv"

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

	"github.com/openziti/zrok/rest_model_zrok"
)

// GetSparklinesHandlerFunc turns a function with the right signature into a get sparklines handler
type GetSparklinesHandlerFunc func(GetSparklinesParams, *rest_model_zrok.Principal) middleware.Responder

// Handle executing the request and returning a response
func (fn GetSparklinesHandlerFunc) Handle(params GetSparklinesParams, principal *rest_model_zrok.Principal) middleware.Responder {
	return fn(params, principal)
}

// GetSparklinesHandler interface for that can handle valid get sparklines params
type GetSparklinesHandler interface {
	Handle(GetSparklinesParams, *rest_model_zrok.Principal) middleware.Responder
}

// NewGetSparklines creates a new http.Handler for the get sparklines operation
func NewGetSparklines(ctx *middleware.Context, handler GetSparklinesHandler) *GetSparklines {
	return &GetSparklines{Context: ctx, Handler: handler}
}

/*
	GetSparklines swagger:route POST /sparklines metadata getSparklines

GetSparklines get sparklines API
*/
type GetSparklines struct {
	Context *middleware.Context
	Handler GetSparklinesHandler
}

func (o *GetSparklines) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
	route, rCtx, _ := o.Context.RouteInfo(r)
	if rCtx != nil {
		*r = *rCtx
	}
	var Params = NewGetSparklinesParams()
	uprinc, aCtx, err := o.Context.Authorize(r, route)
	if err != nil {
		o.Context.Respond(rw, r, route.Produces, route, err)
		return
	}
	if aCtx != nil {
		*r = *aCtx
	}
	var principal *rest_model_zrok.Principal
	if uprinc != nil {
		principal = uprinc.(*rest_model_zrok.Principal) // this is really a rest_model_zrok.Principal, I promise
	}

	if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
		o.Context.Respond(rw, r, route.Produces, route, err)
		return
	}

	res := o.Handler.Handle(Params, principal) // actually handle the request
	o.Context.Respond(rw, r, route.Produces, route, res)

}

// GetSparklinesBody get sparklines body
//
// swagger:model GetSparklinesBody
type GetSparklinesBody struct {

	// account
	Account bool `json:"account,omitempty"`

	// environments
	Environments []string `json:"environments"`

	// shares
	Shares []string `json:"shares"`
}

// Validate validates this get sparklines body
func (o *GetSparklinesBody) Validate(formats strfmt.Registry) error {
	return nil
}

// ContextValidate validates this get sparklines body based on context it is used
func (o *GetSparklinesBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	return nil
}

// MarshalBinary interface implementation
func (o *GetSparklinesBody) MarshalBinary() ([]byte, error) {
	if o == nil {
		return nil, nil
	}
	return swag.WriteJSON(o)
}

// UnmarshalBinary interface implementation
func (o *GetSparklinesBody) UnmarshalBinary(b []byte) error {
	var res GetSparklinesBody
	if err := swag.ReadJSON(b, &res); err != nil {
		return err
	}
	*o = res
	return nil
}

// GetSparklinesOKBody get sparklines o k body
//
// swagger:model GetSparklinesOKBody
type GetSparklinesOKBody struct {

	// sparklines
	Sparklines []*rest_model_zrok.Metrics `json:"sparklines"`
}

// Validate validates this get sparklines o k body
func (o *GetSparklinesOKBody) Validate(formats strfmt.Registry) error {
	var res []error

	if err := o.validateSparklines(formats); err != nil {
		res = append(res, err)
	}

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

func (o *GetSparklinesOKBody) validateSparklines(formats strfmt.Registry) error {
	if swag.IsZero(o.Sparklines) { // not required
		return nil
	}

	for i := 0; i < len(o.Sparklines); i++ {
		if swag.IsZero(o.Sparklines[i]) { // not required
			continue
		}

		if o.Sparklines[i] != nil {
			if err := o.Sparklines[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("getSparklinesOK" + "." + "sparklines" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("getSparklinesOK" + "." + "sparklines" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

// ContextValidate validate this get sparklines o k body based on the context it is used
func (o *GetSparklinesOKBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

	if err := o.contextValidateSparklines(ctx, formats); err != nil {
		res = append(res, err)
	}

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

func (o *GetSparklinesOKBody) contextValidateSparklines(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(o.Sparklines); i++ {

		if o.Sparklines[i] != nil {

			if swag.IsZero(o.Sparklines[i]) { // not required
				return nil
			}

			if err := o.Sparklines[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("getSparklinesOK" + "." + "sparklines" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("getSparklinesOK" + "." + "sparklines" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

// MarshalBinary interface implementation
func (o *GetSparklinesOKBody) MarshalBinary() ([]byte, error) {
	if o == nil {
		return nil, nil
	}
	return swag.WriteJSON(o)
}

// UnmarshalBinary interface implementation
func (o *GetSparklinesOKBody) UnmarshalBinary(b []byte) error {
	var res GetSparklinesOKBody
	if err := swag.ReadJSON(b, &res); err != nil {
		return err
	}
	*o = res
	return nil
}
