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

// NetflowQoSReportTableRow netflow qo s report table row
//
// swagger:model NetflowQoSReportTableRow
type NetflowQoSReportTableRow struct {

	// received
	// Read Only: true
	Received float64 `json:"received,omitempty"`

	// sent
	// Read Only: true
	Sent float64 `json:"sent,omitempty"`

	// type
	// Read Only: true
	Type string `json:"type,omitempty"`
}

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

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

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

		// received
		// Read Only: true
		Received float64 `json:"received,omitempty"`

		// sent
		// Read Only: true
		Sent float64 `json:"sent,omitempty"`

		// type
		// Read Only: true
		Type string `json:"type,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 NetflowQoSReportTableRow

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

	result.Received = data.Received
	result.Sent = data.Sent
	result.Type = data.Type

	*m = result

	return nil
}

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

		// received
		// Read Only: true
		Received float64 `json:"received,omitempty"`

		// sent
		// Read Only: true
		Sent float64 `json:"sent,omitempty"`

		// type
		// Read Only: true
		Type string `json:"type,omitempty"`
	}{

		Received: m.Received,

		Sent: m.Sent,

		Type: m.Type,
	})
	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 qo s report table row
func (m *NetflowQoSReportTableRow) Validate(formats strfmt.Registry) error {
	var res []error

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

// ContextValidate validate this netflow qo s report table row based on the context it is used
func (m *NetflowQoSReportTableRow) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

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

func (m *NetflowQoSReportTableRow) 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 *NetflowQoSReportTableRow) contextValidateReceived(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *NetflowQoSReportTableRow) contextValidateSent(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *NetflowQoSReportTableRow) contextValidateType(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

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

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