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

// BackupOptionsRespDualRegionOptions backup options resp dual region options
//
// swagger:model BackupOptionsRespDualRegionOptions
type BackupOptionsRespDualRegionOptions struct {

	// cluster region
	ClusterRegion *DataflowRegionInfo `json:"cluster_region,omitempty"`

	// region options
	RegionOptions []*BackupOptionsRespRegionOptions `json:"region_options"`
}

// Validate validates this backup options resp dual region options
func (m *BackupOptionsRespDualRegionOptions) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *BackupOptionsRespDualRegionOptions) validateClusterRegion(formats strfmt.Registry) error {
	if swag.IsZero(m.ClusterRegion) { // not required
		return nil
	}

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

	return nil
}

func (m *BackupOptionsRespDualRegionOptions) validateRegionOptions(formats strfmt.Registry) error {
	if swag.IsZero(m.RegionOptions) { // not required
		return nil
	}

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

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

	}

	return nil
}

// ContextValidate validate this backup options resp dual region options based on the context it is used
func (m *BackupOptionsRespDualRegionOptions) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *BackupOptionsRespDualRegionOptions) contextValidateClusterRegion(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *BackupOptionsRespDualRegionOptions) contextValidateRegionOptions(ctx context.Context, formats strfmt.Registry) error {

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

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

	}

	return nil
}

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

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