// 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 (
	"context"
	"strconv"

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

// RowData row data
//
// swagger:model RowData
type RowData struct {

	// cells
	// Read Only: true
	Cells []*CellData `json:"cells,omitempty"`

	// device display name
	// Read Only: true
	DeviceDisplayName string `json:"deviceDisplayName,omitempty"`

	// device Id
	// Read Only: true
	DeviceID int32 `json:"deviceId,omitempty"`
}

// Validate validates this row data
func (m *RowData) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *RowData) validateCells(formats strfmt.Registry) error {
	if swag.IsZero(m.Cells) { // not required
		return nil
	}

	for i := 0; i < len(m.Cells); i++ {
		if swag.IsZero(m.Cells[i]) { // not required
			continue
		}

		if m.Cells[i] != nil {
			if err := m.Cells[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("cells" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

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

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

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

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

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

func (m *RowData) contextValidateCells(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "cells", "body", []*CellData(m.Cells)); err != nil {
		return err
	}

	for i := 0; i < len(m.Cells); i++ {

		if m.Cells[i] != nil {
			if err := m.Cells[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("cells" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *RowData) contextValidateDeviceDisplayName(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *RowData) contextValidateDeviceID(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

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

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