// 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"
	stderrors "errors"

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

// QuotaUsedSize QuotaUsedSize represents the size-based quota usage of a user
//
// swagger:model QuotaUsedSize
type QuotaUsedSize struct {

	// assets
	Assets *QuotaUsedSizeAssets `json:"assets,omitempty"`

	// git
	Git *QuotaUsedSizeGit `json:"git,omitempty"`

	// repos
	Repos *QuotaUsedSizeRepos `json:"repos,omitempty"`
}

// Validate validates this quota used size
func (m *QuotaUsedSize) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

func (m *QuotaUsedSize) validateAssets(formats strfmt.Registry) error {
	if swag.IsZero(m.Assets) { // not required
		return nil
	}

	if m.Assets != nil {
		if err := m.Assets.Validate(formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("assets")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("assets")
			}

			return err
		}
	}

	return nil
}

func (m *QuotaUsedSize) validateGit(formats strfmt.Registry) error {
	if swag.IsZero(m.Git) { // not required
		return nil
	}

	if m.Git != nil {
		if err := m.Git.Validate(formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("git")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("git")
			}

			return err
		}
	}

	return nil
}

func (m *QuotaUsedSize) validateRepos(formats strfmt.Registry) error {
	if swag.IsZero(m.Repos) { // not required
		return nil
	}

	if m.Repos != nil {
		if err := m.Repos.Validate(formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("repos")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("repos")
			}

			return err
		}
	}

	return nil
}

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

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

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

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

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

func (m *QuotaUsedSize) contextValidateAssets(ctx context.Context, formats strfmt.Registry) error {

	if m.Assets != nil {

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

		if err := m.Assets.ContextValidate(ctx, formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("assets")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("assets")
			}

			return err
		}
	}

	return nil
}

func (m *QuotaUsedSize) contextValidateGit(ctx context.Context, formats strfmt.Registry) error {

	if m.Git != nil {

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

		if err := m.Git.ContextValidate(ctx, formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("git")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("git")
			}

			return err
		}
	}

	return nil
}

func (m *QuotaUsedSize) contextValidateRepos(ctx context.Context, formats strfmt.Registry) error {

	if m.Repos != nil {

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

		if err := m.Repos.ContextValidate(ctx, formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("repos")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("repos")
			}

			return err
		}
	}

	return nil
}

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

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