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

// NetflowApplication netflow application
//
// swagger:model NetflowApplication
type NetflowApplication struct {

	// IP
	// Read Only: true
	IP string `json:"IP,omitempty"`

	// client count
	// Read Only: true
	ClientCount int32 `json:"clientCount,omitempty"`

	// destination m bytes
	// Read Only: true
	DestinationMBytes float64 `json:"destinationMBytes,omitempty"`

	// dns
	// Read Only: true
	DNS string `json:"dns,omitempty"`

	// first epoch in sec
	// Read Only: true
	FirstEpochInSec int64 `json:"firstEpochInSec,omitempty"`

	// flow count
	// Read Only: true
	FlowCount int64 `json:"flowCount,omitempty"`

	// last epoch in sec
	// Read Only: true
	LastEpochInSec int64 `json:"lastEpochInSec,omitempty"`

	// percent usage
	// Read Only: true
	PercentUsage float64 `json:"percentUsage,omitempty"`

	// port
	// Read Only: true
	Port int32 `json:"port,omitempty"`

	// protocol
	// Read Only: true
	Protocol string `json:"protocol,omitempty"`

	// source m bytes
	// Read Only: true
	SourceMBytes float64 `json:"sourceMBytes,omitempty"`

	// usage
	// Read Only: true
	Usage float64 `json:"usage,omitempty"`
}

// DataType gets the data type of this subtype
func (m *NetflowApplication) DataType() string {
	return "application"
}

// SetDataType sets the data type of this subtype
func (m *NetflowApplication) SetDataType(val string) {
}

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

		// IP
		// Read Only: true
		IP string `json:"IP,omitempty"`

		// client count
		// Read Only: true
		ClientCount int32 `json:"clientCount,omitempty"`

		// destination m bytes
		// Read Only: true
		DestinationMBytes float64 `json:"destinationMBytes,omitempty"`

		// dns
		// Read Only: true
		DNS string `json:"dns,omitempty"`

		// first epoch in sec
		// Read Only: true
		FirstEpochInSec int64 `json:"firstEpochInSec,omitempty"`

		// flow count
		// Read Only: true
		FlowCount int64 `json:"flowCount,omitempty"`

		// last epoch in sec
		// Read Only: true
		LastEpochInSec int64 `json:"lastEpochInSec,omitempty"`

		// percent usage
		// Read Only: true
		PercentUsage float64 `json:"percentUsage,omitempty"`

		// port
		// Read Only: true
		Port int32 `json:"port,omitempty"`

		// protocol
		// Read Only: true
		Protocol string `json:"protocol,omitempty"`

		// source m bytes
		// Read Only: true
		SourceMBytes float64 `json:"sourceMBytes,omitempty"`

		// usage
		// Read Only: true
		Usage float64 `json:"usage,omitempty"`
	}
	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.*/

		DataType string `json:"dataType,omitempty"`
	}
	buf = bytes.NewBuffer(raw)
	dec = json.NewDecoder(buf)
	dec.UseNumber()

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

	var result NetflowApplication

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

	result.IP = data.IP
	result.ClientCount = data.ClientCount
	result.DestinationMBytes = data.DestinationMBytes
	result.DNS = data.DNS
	result.FirstEpochInSec = data.FirstEpochInSec
	result.FlowCount = data.FlowCount
	result.LastEpochInSec = data.LastEpochInSec
	result.PercentUsage = data.PercentUsage
	result.Port = data.Port
	result.Protocol = data.Protocol
	result.SourceMBytes = data.SourceMBytes
	result.Usage = data.Usage

	*m = result

	return nil
}

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

		// IP
		// Read Only: true
		IP string `json:"IP,omitempty"`

		// client count
		// Read Only: true
		ClientCount int32 `json:"clientCount,omitempty"`

		// destination m bytes
		// Read Only: true
		DestinationMBytes float64 `json:"destinationMBytes,omitempty"`

		// dns
		// Read Only: true
		DNS string `json:"dns,omitempty"`

		// first epoch in sec
		// Read Only: true
		FirstEpochInSec int64 `json:"firstEpochInSec,omitempty"`

		// flow count
		// Read Only: true
		FlowCount int64 `json:"flowCount,omitempty"`

		// last epoch in sec
		// Read Only: true
		LastEpochInSec int64 `json:"lastEpochInSec,omitempty"`

		// percent usage
		// Read Only: true
		PercentUsage float64 `json:"percentUsage,omitempty"`

		// port
		// Read Only: true
		Port int32 `json:"port,omitempty"`

		// protocol
		// Read Only: true
		Protocol string `json:"protocol,omitempty"`

		// source m bytes
		// Read Only: true
		SourceMBytes float64 `json:"sourceMBytes,omitempty"`

		// usage
		// Read Only: true
		Usage float64 `json:"usage,omitempty"`
	}{

		IP: m.IP,

		ClientCount: m.ClientCount,

		DestinationMBytes: m.DestinationMBytes,

		DNS: m.DNS,

		FirstEpochInSec: m.FirstEpochInSec,

		FlowCount: m.FlowCount,

		LastEpochInSec: m.LastEpochInSec,

		PercentUsage: m.PercentUsage,

		Port: m.Port,

		Protocol: m.Protocol,

		SourceMBytes: m.SourceMBytes,

		Usage: m.Usage,
	})
	if err != nil {
		return nil, err
	}
	b2, err = json.Marshal(struct {
		DataType string `json:"dataType,omitempty"`
	}{

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

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

// Validate validates this netflow application
func (m *NetflowApplication) Validate(formats strfmt.Registry) error {
	var res []error

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

// ContextValidate validate this netflow application based on the context it is used
func (m *NetflowApplication) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

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

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

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

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

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

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

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

func (m *NetflowApplication) contextValidateDataType(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "dataType", "body", string(m.DataType())); err != nil {
		return err
	}

	return nil
}

func (m *NetflowApplication) contextValidateIP(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "IP", "body", string(m.IP)); err != nil {
		return err
	}

	return nil
}

func (m *NetflowApplication) contextValidateClientCount(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "clientCount", "body", int32(m.ClientCount)); err != nil {
		return err
	}

	return nil
}

func (m *NetflowApplication) contextValidateDestinationMBytes(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "destinationMBytes", "body", float64(m.DestinationMBytes)); err != nil {
		return err
	}

	return nil
}

func (m *NetflowApplication) contextValidateDNS(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "dns", "body", string(m.DNS)); err != nil {
		return err
	}

	return nil
}

func (m *NetflowApplication) contextValidateFirstEpochInSec(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "firstEpochInSec", "body", int64(m.FirstEpochInSec)); err != nil {
		return err
	}

	return nil
}

func (m *NetflowApplication) contextValidateFlowCount(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "flowCount", "body", int64(m.FlowCount)); err != nil {
		return err
	}

	return nil
}

func (m *NetflowApplication) contextValidateLastEpochInSec(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "lastEpochInSec", "body", int64(m.LastEpochInSec)); err != nil {
		return err
	}

	return nil
}

func (m *NetflowApplication) contextValidatePercentUsage(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "percentUsage", "body", float64(m.PercentUsage)); err != nil {
		return err
	}

	return nil
}

func (m *NetflowApplication) contextValidatePort(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "port", "body", int32(m.Port)); err != nil {
		return err
	}

	return nil
}

func (m *NetflowApplication) contextValidateProtocol(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "protocol", "body", string(m.Protocol)); err != nil {
		return err
	}

	return nil
}

func (m *NetflowApplication) contextValidateSourceMBytes(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "sourceMBytes", "body", float64(m.SourceMBytes)); err != nil {
		return err
	}

	return nil
}

func (m *NetflowApplication) contextValidateUsage(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "usage", "body", float64(m.Usage)); err != nil {
		return err
	}

	return nil
}

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

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