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

// JDBCAutoDiscoveryMethod j d b c auto discovery method
//
// swagger:model JDBCAutoDiscoveryMethod
type JDBCAutoDiscoveryMethod struct {

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

	// query
	// Required: true
	Query *string `json:"query"`

	// separator
	Separator string `json:"separator,omitempty"`

	// sid
	Sid string `json:"sid,omitempty"`

	// type
	// Required: true
	Type *string `json:"type"`

	// url
	// Required: true
	URL *string `json:"url"`
}

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

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

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

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

		// query
		// Required: true
		Query *string `json:"query"`

		// separator
		Separator string `json:"separator,omitempty"`

		// sid
		Sid string `json:"sid,omitempty"`

		// type
		// Required: true
		Type *string `json:"type"`

		// url
		// Required: true
		URL *string `json:"url"`
	}
	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 JDBCAutoDiscoveryMethod

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

	result.Ports = data.Ports
	result.Query = data.Query
	result.Separator = data.Separator
	result.Sid = data.Sid
	result.Type = data.Type
	result.URL = data.URL

	*m = result

	return nil
}

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

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

		// query
		// Required: true
		Query *string `json:"query"`

		// separator
		Separator string `json:"separator,omitempty"`

		// sid
		Sid string `json:"sid,omitempty"`

		// type
		// Required: true
		Type *string `json:"type"`

		// url
		// Required: true
		URL *string `json:"url"`
	}{

		Ports: m.Ports,

		Query: m.Query,

		Separator: m.Separator,

		Sid: m.Sid,

		Type: m.Type,

		URL: m.URL,
	})
	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 j d b c auto discovery method
func (m *JDBCAutoDiscoveryMethod) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

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

	return nil
}

func (m *JDBCAutoDiscoveryMethod) validateQuery(formats strfmt.Registry) error {

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

	return nil
}

func (m *JDBCAutoDiscoveryMethod) validateType(formats strfmt.Registry) error {

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

	return nil
}

func (m *JDBCAutoDiscoveryMethod) validateURL(formats strfmt.Registry) error {

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

	return nil
}

// ContextValidate validate this j d b c auto discovery method based on the context it is used
func (m *JDBCAutoDiscoveryMethod) 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 *JDBCAutoDiscoveryMethod) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}

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