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

// DynamicTableWidgetColumn dynamic table widget column
//
// swagger:model DynamicTableWidgetColumn
type DynamicTableWidgetColumn struct {

	// The threshold of color changes
	ColorThresholds []*ColorThreshold `json:"colorThresholds,omitempty"`

	// The name for the column
	// Required: true
	ColumnName *string `json:"columnName"`

	// The id of the datapoint
	// Required: true
	DataPointID *int32 `json:"dataPointId"`

	// The name of the datapoint
	// Read Only: true
	DataPointName string `json:"dataPointName,omitempty"`

	// The display type, it includes three options: raw|percent|colorBar
	DisplayType string `json:"displayType,omitempty"`

	// Whether or not forecasting is enabled
	EnableForecast bool `json:"enableForecast,omitempty"`

	// The maximum value of the table widget
	MaxValue float64 `json:"maxValue,omitempty"`

	// The minimum value of the table widget
	MinValue float64 `json:"minValue,omitempty"`

	// The number of decimal points to round the value to. Options are 0, 1 and 2
	RoundingDecimal int32 `json:"roundingDecimal,omitempty"`

	// The expression in this field will be performed on the datapoint. The Column name should be referenced as the datapoint
	Rpn string `json:"rpn,omitempty"`

	// The unit label
	UnitLabel string `json:"unitLabel,omitempty"`
}

// Validate validates this dynamic table widget column
func (m *DynamicTableWidgetColumn) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

func (m *DynamicTableWidgetColumn) validateColorThresholds(formats strfmt.Registry) error {
	if swag.IsZero(m.ColorThresholds) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *DynamicTableWidgetColumn) validateColumnName(formats strfmt.Registry) error {

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

	return nil
}

func (m *DynamicTableWidgetColumn) validateDataPointID(formats strfmt.Registry) error {

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

	return nil
}

// ContextValidate validate this dynamic table widget column based on the context it is used
func (m *DynamicTableWidgetColumn) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *DynamicTableWidgetColumn) contextValidateColorThresholds(ctx context.Context, formats strfmt.Registry) error {

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

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

	}

	return nil
}

func (m *DynamicTableWidgetColumn) contextValidateDataPointName(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

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

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