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

// QuotaUsedAttachment QuotaUsedAttachment represents an attachment counting towards a user's quota
//
// swagger:model QuotaUsedAttachment
type QuotaUsedAttachment struct {

	// API URL for the attachment
	APIURL string `json:"api_url,omitempty"`

	// Filename of the attachment
	Name string `json:"name,omitempty"`

	// Size of the attachment (in bytes)
	Size int64 `json:"size,omitempty"`

	// contained in
	ContainedIn *ContainedIn `json:"contained_in,omitempty"`
}

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

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

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

func (m *QuotaUsedAttachment) validateContainedIn(formats strfmt.Registry) error {
	if swag.IsZero(m.ContainedIn) { // not required
		return nil
	}

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

			return err
		}
	}

	return nil
}

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

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

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

func (m *QuotaUsedAttachment) contextValidateContainedIn(ctx context.Context, formats strfmt.Registry) error {

	if m.ContainedIn != nil {

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

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

			return err
		}
	}

	return nil
}

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

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

// ContainedIn Context for the attachment: URLs to the containing object
//
// swagger:model ContainedIn
type ContainedIn struct {

	// API URL for the object that contains this attachment
	APIURL string `json:"api_url,omitempty"`

	// HTML URL for the object that contains this attachment
	HTMLURL string `json:"html_url,omitempty"`
}

// Validate validates this contained in
func (m *ContainedIn) Validate(formats strfmt.Registry) error {
	return nil
}

// ContextValidate validates this contained in based on context it is used
func (m *ContainedIn) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	return nil
}

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

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