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

// OpenapiListBranchesResp openapi list branches resp
//
// swagger:model openapiListBranchesResp
type OpenapiListBranchesResp struct {

	// The items of branches in the cluster.
	// Required: true
	Branches []*OpenapiGetBranchResp `json:"branches"`

	// The total number of branches in the cluster.
	// Required: true
	Total *string `json:"total"`
}

// Validate validates this openapi list branches resp
func (m *OpenapiListBranchesResp) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *OpenapiListBranchesResp) validateBranches(formats strfmt.Registry) error {

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

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

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

	}

	return nil
}

func (m *OpenapiListBranchesResp) validateTotal(formats strfmt.Registry) error {

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

	return nil
}

// ContextValidate validate this openapi list branches resp based on the context it is used
func (m *OpenapiListBranchesResp) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

func (m *OpenapiListBranchesResp) contextValidateBranches(ctx context.Context, formats strfmt.Registry) error {

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

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

	}

	return nil
}

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

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