// Code generated by go-swagger; DO NOT EDIT.

package ops

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

// EntityClusterMaintenanceTask entity cluster maintenance task
//
// swagger:model entity.ClusterMaintenanceTask
type EntityClusterMaintenanceTask struct {

	// create at
	CreateAt string `json:"create_at,omitempty"`

	// deadline
	Deadline string `json:"deadline,omitempty"`

	// description
	Description string `json:"description,omitempty"`

	// executions
	Executions []*EntityClusterMaintenanceExecution `json:"executions"`

	// id
	ID int64 `json:"id,omitempty"`

	// project id
	// Example: 0
	ProjectID string `json:"project_id,omitempty"`

	// schedule time
	ScheduleTime string `json:"schedule_time,omitempty"`

	// status
	Status EntityClusterMaintenanceTaskStatus `json:"status,omitempty"`
}

// Validate validates this entity cluster maintenance task
func (m *EntityClusterMaintenanceTask) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *EntityClusterMaintenanceTask) validateExecutions(formats strfmt.Registry) error {
	if swag.IsZero(m.Executions) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *EntityClusterMaintenanceTask) validateStatus(formats strfmt.Registry) error {
	if swag.IsZero(m.Status) { // not required
		return nil
	}

	if err := m.Status.Validate(formats); err != nil {
		if ve, ok := err.(*errors.Validation); ok {
			return ve.ValidateName("status")
		} else if ce, ok := err.(*errors.CompositeError); ok {
			return ce.ValidateName("status")
		}
		return err
	}

	return nil
}

// ContextValidate validate this entity cluster maintenance task based on the context it is used
func (m *EntityClusterMaintenanceTask) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *EntityClusterMaintenanceTask) contextValidateExecutions(ctx context.Context, formats strfmt.Registry) error {

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

		if m.Executions[i] != nil {

			if swag.IsZero(m.Executions[i]) { // not required
				return nil
			}

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

	}

	return nil
}

func (m *EntityClusterMaintenanceTask) contextValidateStatus(ctx context.Context, formats strfmt.Registry) error {

	if swag.IsZero(m.Status) { // not required
		return nil
	}

	if err := m.Status.ContextValidate(ctx, formats); err != nil {
		if ve, ok := err.(*errors.Validation); ok {
			return ve.ValidateName("status")
		} else if ce, ok := err.(*errors.CompositeError); ok {
			return ce.ValidateName("status")
		}
		return err
	}

	return nil
}

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

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