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

// V1alpha1CredentialStatus CredentialStatus represents the credentialStatus property of a Verifiable Credential.
// more information can be found [here]
//
// swagger:model v1alpha1CredentialStatus
//
// [here]: https://www.w3.org/TR/vc-data-model-2.0/#status
type V1alpha1CredentialStatus struct {

	// The creation date and time of the status
	CreatedAt V1alpha1Time `json:"createdAt,omitempty"`

	// The URL identifying the schema file
	ID string `json:"id,omitempty"`

	// The value of the purpose for the status entry
	Purpose *V1alpha1CredentialStatusPurpose `json:"purpose,omitempty"`

	// Type specifies the type of the file
	Type string `json:"type,omitempty"`
}

// Validate validates this v1alpha1 credential status
func (m *V1alpha1CredentialStatus) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *V1alpha1CredentialStatus) validatePurpose(formats strfmt.Registry) error {
	if swag.IsZero(m.Purpose) { // not required
		return nil
	}

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

			return err
		}
	}

	return nil
}

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

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

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

func (m *V1alpha1CredentialStatus) contextValidatePurpose(ctx context.Context, formats strfmt.Registry) error {

	if m.Purpose != nil {

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

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

			return err
		}
	}

	return nil
}

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

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