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

package models

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

import (
	"bytes"
	"context"
	"encoding/json"

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

// HTTPAutoDiscoveryMethod Http auto discovery method
//
// swagger:model HttpAutoDiscoveryMethod
type HTTPAutoDiscoveryMethod struct {

	// case sensitive
	// Required: true
	CaseSensitive *bool `json:"caseSensitive"`

	// follow redirect
	// Required: true
	FollowRedirect *bool `json:"followRedirect"`

	// ports
	// Required: true
	Ports *string `json:"ports"`

	// regex
	// Required: true
	Regex *string `json:"regex"`

	// uri
	// Required: true
	URI *string `json:"uri"`

	// use s s l
	// Required: true
	UseSSL *bool `json:"useSSL"`
}

// Name gets the name of this subtype
func (m *HTTPAutoDiscoveryMethod) Name() string {
	return "ad_http"
}

// SetName sets the name of this subtype
func (m *HTTPAutoDiscoveryMethod) SetName(val string) {
}

// UnmarshalJSON unmarshals this object with a polymorphic type from a JSON structure
func (m *HTTPAutoDiscoveryMethod) UnmarshalJSON(raw []byte) error {
	var data struct {

		// case sensitive
		// Required: true
		CaseSensitive *bool `json:"caseSensitive"`

		// follow redirect
		// Required: true
		FollowRedirect *bool `json:"followRedirect"`

		// ports
		// Required: true
		Ports *string `json:"ports"`

		// regex
		// Required: true
		Regex *string `json:"regex"`

		// uri
		// Required: true
		URI *string `json:"uri"`

		// use s s l
		// Required: true
		UseSSL *bool `json:"useSSL"`
	}
	buf := bytes.NewBuffer(raw)
	dec := json.NewDecoder(buf)
	dec.UseNumber()

	if err := dec.Decode(&data); err != nil {
		return err
	}

	var base struct {
		/* Just the base type fields. Used for unmashalling polymorphic types.*/

		Name string `json:"name"`
	}
	buf = bytes.NewBuffer(raw)
	dec = json.NewDecoder(buf)
	dec.UseNumber()

	if err := dec.Decode(&base); err != nil {
		return err
	}

	var result HTTPAutoDiscoveryMethod

	if base.Name != result.Name() {
		/* Not the type we're looking for. */
		return errors.New(422, "invalid name value: %q", base.Name)
	}

	result.CaseSensitive = data.CaseSensitive
	result.FollowRedirect = data.FollowRedirect
	result.Ports = data.Ports
	result.Regex = data.Regex
	result.URI = data.URI
	result.UseSSL = data.UseSSL

	*m = result

	return nil
}

// MarshalJSON marshals this object with a polymorphic type to a JSON structure
func (m HTTPAutoDiscoveryMethod) MarshalJSON() ([]byte, error) {
	var b1, b2, b3 []byte
	var err error
	b1, err = json.Marshal(struct {

		// case sensitive
		// Required: true
		CaseSensitive *bool `json:"caseSensitive"`

		// follow redirect
		// Required: true
		FollowRedirect *bool `json:"followRedirect"`

		// ports
		// Required: true
		Ports *string `json:"ports"`

		// regex
		// Required: true
		Regex *string `json:"regex"`

		// uri
		// Required: true
		URI *string `json:"uri"`

		// use s s l
		// Required: true
		UseSSL *bool `json:"useSSL"`
	}{

		CaseSensitive: m.CaseSensitive,

		FollowRedirect: m.FollowRedirect,

		Ports: m.Ports,

		Regex: m.Regex,

		URI: m.URI,

		UseSSL: m.UseSSL,
	})
	if err != nil {
		return nil, err
	}
	b2, err = json.Marshal(struct {
		Name string `json:"name"`
	}{

		Name: m.Name(),
	})
	if err != nil {
		return nil, err
	}

	return swag.ConcatJSON(b1, b2, b3), nil
}

// Validate validates this Http auto discovery method
func (m *HTTPAutoDiscoveryMethod) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

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

func (m *HTTPAutoDiscoveryMethod) validateCaseSensitive(formats strfmt.Registry) error {

	if err := validate.Required("caseSensitive", "body", m.CaseSensitive); err != nil {
		return err
	}

	return nil
}

func (m *HTTPAutoDiscoveryMethod) validateFollowRedirect(formats strfmt.Registry) error {

	if err := validate.Required("followRedirect", "body", m.FollowRedirect); err != nil {
		return err
	}

	return nil
}

func (m *HTTPAutoDiscoveryMethod) validatePorts(formats strfmt.Registry) error {

	if err := validate.Required("ports", "body", m.Ports); err != nil {
		return err
	}

	return nil
}

func (m *HTTPAutoDiscoveryMethod) validateRegex(formats strfmt.Registry) error {

	if err := validate.Required("regex", "body", m.Regex); err != nil {
		return err
	}

	return nil
}

func (m *HTTPAutoDiscoveryMethod) validateURI(formats strfmt.Registry) error {

	if err := validate.Required("uri", "body", m.URI); err != nil {
		return err
	}

	return nil
}

func (m *HTTPAutoDiscoveryMethod) validateUseSSL(formats strfmt.Registry) error {

	if err := validate.Required("useSSL", "body", m.UseSSL); err != nil {
		return err
	}

	return nil
}

// ContextValidate validate this Http auto discovery method based on the context it is used
func (m *HTTPAutoDiscoveryMethod) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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