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

package model

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

import (
	"context"

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

// Commonv1beta1Region Message for describing a region for deploying TiDB Serverless clusters.
//
// swagger:model commonv1beta1Region
type Commonv1beta1Region struct {

	// Output only. User-friendly display name of the region.
	// Read Only: true
	DisplayName string `json:"displayName,omitempty"`

	// id
	// Example: us-west-2
	// Read Only: true
	ID string `json:"id,omitempty"`

	// Required. The unique name of the region.
	// Example: regions/aws-us-west-2
	// Required: true
	// Pattern: ^regions/(aws|gcp|azure)-(.+)$
	Name *string `json:"name"`

	// Output only. The cloud provider for the region.
	// Read Only: true
	Provider *V1beta1RegionCloudProvider `json:"provider,omitempty"`
}

// Validate validates this commonv1beta1 region
func (m *Commonv1beta1Region) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *Commonv1beta1Region) validateName(formats strfmt.Registry) error {

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

	if err := validate.Pattern("name", "body", *m.Name, `^regions/(aws|gcp|azure)-(.+)$`); err != nil {
		return err
	}

	return nil
}

func (m *Commonv1beta1Region) validateProvider(formats strfmt.Registry) error {
	if swag.IsZero(m.Provider) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

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

func (m *Commonv1beta1Region) contextValidateDisplayName(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *Commonv1beta1Region) contextValidateID(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *Commonv1beta1Region) contextValidateProvider(ctx context.Context, formats strfmt.Registry) error {

	if m.Provider != nil {

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

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

	return nil
}

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

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