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

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

	// Storage size used for the user's artifacts
	Artifacts int64 `json:"artifacts,omitempty"`

	// attachments
	Attachments *QuotaUsedSizeAssetsAttachments `json:"attachments,omitempty"`

	// packages
	Packages *QuotaUsedSizeAssetsPackages `json:"packages,omitempty"`
}

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

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

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

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

func (m *QuotaUsedSizeAssets) validateAttachments(formats strfmt.Registry) error {
	if swag.IsZero(m.Attachments) { // not required
		return nil
	}

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

			return err
		}
	}

	return nil
}

func (m *QuotaUsedSizeAssets) validatePackages(formats strfmt.Registry) error {
	if swag.IsZero(m.Packages) { // not required
		return nil
	}

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

			return err
		}
	}

	return nil
}

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

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

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

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

func (m *QuotaUsedSizeAssets) contextValidateAttachments(ctx context.Context, formats strfmt.Registry) error {

	if m.Attachments != nil {

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

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

			return err
		}
	}

	return nil
}

func (m *QuotaUsedSizeAssets) contextValidatePackages(ctx context.Context, formats strfmt.Registry) error {

	if m.Packages != nil {

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

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

			return err
		}
	}

	return nil
}

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

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