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

package admin

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

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

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

// CreateOrganizationHandlerFunc turns a function with the right signature into a create organization handler
type CreateOrganizationHandlerFunc func(CreateOrganizationParams, *rest_model_zrok.Principal) middleware.Responder

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

// CreateOrganizationHandler interface for that can handle valid create organization params
type CreateOrganizationHandler interface {
	Handle(CreateOrganizationParams, *rest_model_zrok.Principal) middleware.Responder
}

// NewCreateOrganization creates a new http.Handler for the create organization operation
func NewCreateOrganization(ctx *middleware.Context, handler CreateOrganizationHandler) *CreateOrganization {
	return &CreateOrganization{Context: ctx, Handler: handler}
}

/*
	CreateOrganization swagger:route POST /organization admin createOrganization

CreateOrganization create organization API
*/
type CreateOrganization struct {
	Context *middleware.Context
	Handler CreateOrganizationHandler
}

func (o *CreateOrganization) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
	route, rCtx, _ := o.Context.RouteInfo(r)
	if rCtx != nil {
		*r = *rCtx
	}
	var Params = NewCreateOrganizationParams()
	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)

}

// CreateOrganizationBody create organization body
//
// swagger:model CreateOrganizationBody
type CreateOrganizationBody struct {

	// description
	Description string `json:"description,omitempty"`
}

// Validate validates this create organization body
func (o *CreateOrganizationBody) Validate(formats strfmt.Registry) error {
	return nil
}

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

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

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

// CreateOrganizationCreatedBody create organization created body
//
// swagger:model CreateOrganizationCreatedBody
type CreateOrganizationCreatedBody struct {

	// token
	Token string `json:"token,omitempty"`
}

// Validate validates this create organization created body
func (o *CreateOrganizationCreatedBody) Validate(formats strfmt.Registry) error {
	return nil
}

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

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

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