// Code generated by go-swagger; DO NOT EDIT.

// (c) 2012-2020 by Taxnexus, Inc.
// All rights reserved worldwide.
// Proprietary product; unlicensed use is not allowed

package members_models

import (
	"context"
	"encoding/json"

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

// AuthorizedClient authorized client
//
// swagger:model AuthorizedClient
type AuthorizedClient struct {
	AuditFields

	// approved at
	// Read Only: true
	// Format: date-time
	ApprovedAt *strfmt.DateTime `json:"approvedAt,omitempty"`

	// client identifier
	// Required: true
	// Max Length: 255
	// Min Length: 1
	ClientIdentifier *string `json:"clientIdentifier"`

	// client type
	// Required: true
	// Enum: ["mcp","api"]
	ClientType *string `json:"clientType"`

	// client Uri
	// Max Length: 2048
	ClientURI *string `json:"clientUri,omitempty"`

	// display name
	// Required: true
	// Max Length: 255
	// Min Length: 1
	DisplayName *string `json:"displayName"`

	// expires at
	// Format: date-time
	ExpiresAt *strfmt.DateTime `json:"expiresAt,omitempty"`

	// Non-secret external reference.
	// Max Length: 255
	ExternalConnectionID *string `json:"externalConnectionId,omitempty"`

	// last used at
	// Read Only: true
	// Format: date-time
	LastUsedAt *strfmt.DateTime `json:"lastUsedAt,omitempty"`

	// revoked at
	// Read Only: true
	// Format: date-time
	RevokedAt *strfmt.DateTime `json:"revokedAt,omitempty"`

	// revoked by Id
	// Read Only: true
	// Format: uuid
	RevokedByID *strfmt.UUID `json:"revokedById,omitempty"`

	// software Id
	// Max Length: 255
	SoftwareID *string `json:"softwareId,omitempty"`

	// software version
	// Max Length: 80
	SoftwareVersion *string `json:"softwareVersion,omitempty"`

	// status
	// Required: true
	// Enum: ["pending","active","revoked","expired"]
	Status *string `json:"status"`

	// tenant Id
	// Required: true
	// Format: uuid
	TenantID *strfmt.UUID `json:"tenantId"`

	// Null means tenant-level; non-null must belong to the tenant.
	// Format: uuid
	UserID *strfmt.UUID `json:"userId,omitempty"`
}

// UnmarshalJSON unmarshals this object from a JSON structure
func (m *AuthorizedClient) UnmarshalJSON(raw []byte) error {
	// AO0
	var aO0 AuditFields
	if err := jsonutils.ReadJSON(raw, &aO0); err != nil {
		return err
	}
	m.AuditFields = aO0

	// AO1
	var dataAO1 struct {
		ApprovedAt *strfmt.DateTime `json:"approvedAt,omitempty"`

		ClientIdentifier *string `json:"clientIdentifier"`

		ClientType *string `json:"clientType"`

		ClientURI *string `json:"clientUri,omitempty"`

		DisplayName *string `json:"displayName"`

		ExpiresAt *strfmt.DateTime `json:"expiresAt,omitempty"`

		ExternalConnectionID *string `json:"externalConnectionId,omitempty"`

		LastUsedAt *strfmt.DateTime `json:"lastUsedAt,omitempty"`

		RevokedAt *strfmt.DateTime `json:"revokedAt,omitempty"`

		RevokedByID *strfmt.UUID `json:"revokedById,omitempty"`

		SoftwareID *string `json:"softwareId,omitempty"`

		SoftwareVersion *string `json:"softwareVersion,omitempty"`

		Status *string `json:"status"`

		TenantID *strfmt.UUID `json:"tenantId"`

		UserID *strfmt.UUID `json:"userId,omitempty"`
	}
	if err := jsonutils.ReadJSON(raw, &dataAO1); err != nil {
		return err
	}

	m.ApprovedAt = dataAO1.ApprovedAt

	m.ClientIdentifier = dataAO1.ClientIdentifier

	m.ClientType = dataAO1.ClientType

	m.ClientURI = dataAO1.ClientURI

	m.DisplayName = dataAO1.DisplayName

	m.ExpiresAt = dataAO1.ExpiresAt

	m.ExternalConnectionID = dataAO1.ExternalConnectionID

	m.LastUsedAt = dataAO1.LastUsedAt

	m.RevokedAt = dataAO1.RevokedAt

	m.RevokedByID = dataAO1.RevokedByID

	m.SoftwareID = dataAO1.SoftwareID

	m.SoftwareVersion = dataAO1.SoftwareVersion

	m.Status = dataAO1.Status

	m.TenantID = dataAO1.TenantID

	m.UserID = dataAO1.UserID

	return nil
}

// MarshalJSON marshals this object to a JSON structure
func (m AuthorizedClient) MarshalJSON() ([]byte, error) {
	_parts := make([][]byte, 0, 2)

	aO0, err := jsonutils.WriteJSON(m.AuditFields)
	if err != nil {
		return nil, err
	}
	_parts = append(_parts, aO0)
	var dataAO1 struct {
		ApprovedAt *strfmt.DateTime `json:"approvedAt,omitempty"`

		ClientIdentifier *string `json:"clientIdentifier"`

		ClientType *string `json:"clientType"`

		ClientURI *string `json:"clientUri,omitempty"`

		DisplayName *string `json:"displayName"`

		ExpiresAt *strfmt.DateTime `json:"expiresAt,omitempty"`

		ExternalConnectionID *string `json:"externalConnectionId,omitempty"`

		LastUsedAt *strfmt.DateTime `json:"lastUsedAt,omitempty"`

		RevokedAt *strfmt.DateTime `json:"revokedAt,omitempty"`

		RevokedByID *strfmt.UUID `json:"revokedById,omitempty"`

		SoftwareID *string `json:"softwareId,omitempty"`

		SoftwareVersion *string `json:"softwareVersion,omitempty"`

		Status *string `json:"status"`

		TenantID *strfmt.UUID `json:"tenantId"`

		UserID *strfmt.UUID `json:"userId,omitempty"`
	}

	dataAO1.ApprovedAt = m.ApprovedAt

	dataAO1.ClientIdentifier = m.ClientIdentifier

	dataAO1.ClientType = m.ClientType

	dataAO1.ClientURI = m.ClientURI

	dataAO1.DisplayName = m.DisplayName

	dataAO1.ExpiresAt = m.ExpiresAt

	dataAO1.ExternalConnectionID = m.ExternalConnectionID

	dataAO1.LastUsedAt = m.LastUsedAt

	dataAO1.RevokedAt = m.RevokedAt

	dataAO1.RevokedByID = m.RevokedByID

	dataAO1.SoftwareID = m.SoftwareID

	dataAO1.SoftwareVersion = m.SoftwareVersion

	dataAO1.Status = m.Status

	dataAO1.TenantID = m.TenantID

	dataAO1.UserID = m.UserID

	jsonDataAO1, errAO1 := jsonutils.WriteJSON(dataAO1)
	if errAO1 != nil {
		return nil, errAO1
	}
	_parts = append(_parts, jsonDataAO1)
	return jsonutils.ConcatJSON(_parts...), nil
}

// Validate validates this authorized client
func (m *AuthorizedClient) Validate(formats strfmt.Registry) error {
	var res []error

	// validation for a type composition with AuditFields
	if err := m.AuditFields.Validate(formats); err != nil {
		res = append(res, err)
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

func (m *AuthorizedClient) validateApprovedAt(formats strfmt.Registry) error {

	if typeutils.IsZero(m.ApprovedAt) { // not required
		return nil
	}

	if err := validate.FormatOf("approvedAt", "body", "date-time", m.ApprovedAt.String(), formats); err != nil {
		return err
	}

	return nil
}

func (m *AuthorizedClient) validateClientIdentifier(formats strfmt.Registry) error {

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

	if err := validate.MinLength("clientIdentifier", "body", *m.ClientIdentifier, 1); err != nil {
		return err
	}

	if err := validate.MaxLength("clientIdentifier", "body", *m.ClientIdentifier, 255); err != nil {
		return err
	}

	return nil
}

var authorizedClientTypeClientTypePropEnum []any

func init() {
	var res []string
	if err := json.Unmarshal([]byte(`["mcp","api"]`), &res); err != nil {
		panic(err)
	}
	for _, v := range res {
		authorizedClientTypeClientTypePropEnum = append(authorizedClientTypeClientTypePropEnum, v)
	}
}

// property enum
func (m *AuthorizedClient) validateClientTypeEnum(path, location string, value string) error {
	if err := validate.EnumCase(path, location, value, authorizedClientTypeClientTypePropEnum, true); err != nil {
		return err
	}
	return nil
}

func (m *AuthorizedClient) validateClientType(formats strfmt.Registry) error {

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

	// value enum
	if err := m.validateClientTypeEnum("clientType", "body", *m.ClientType); err != nil {
		return err
	}

	return nil
}

func (m *AuthorizedClient) validateClientURI(formats strfmt.Registry) error {

	if typeutils.IsZero(m.ClientURI) { // not required
		return nil
	}

	if err := validate.MaxLength("clientUri", "body", *m.ClientURI, 2048); err != nil {
		return err
	}

	return nil
}

func (m *AuthorizedClient) validateDisplayName(formats strfmt.Registry) error {

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

	if err := validate.MinLength("displayName", "body", *m.DisplayName, 1); err != nil {
		return err
	}

	if err := validate.MaxLength("displayName", "body", *m.DisplayName, 255); err != nil {
		return err
	}

	return nil
}

func (m *AuthorizedClient) validateExpiresAt(formats strfmt.Registry) error {

	if typeutils.IsZero(m.ExpiresAt) { // not required
		return nil
	}

	if err := validate.FormatOf("expiresAt", "body", "date-time", m.ExpiresAt.String(), formats); err != nil {
		return err
	}

	return nil
}

func (m *AuthorizedClient) validateExternalConnectionID(formats strfmt.Registry) error {

	if typeutils.IsZero(m.ExternalConnectionID) { // not required
		return nil
	}

	if err := validate.MaxLength("externalConnectionId", "body", *m.ExternalConnectionID, 255); err != nil {
		return err
	}

	return nil
}

func (m *AuthorizedClient) validateLastUsedAt(formats strfmt.Registry) error {

	if typeutils.IsZero(m.LastUsedAt) { // not required
		return nil
	}

	if err := validate.FormatOf("lastUsedAt", "body", "date-time", m.LastUsedAt.String(), formats); err != nil {
		return err
	}

	return nil
}

func (m *AuthorizedClient) validateRevokedAt(formats strfmt.Registry) error {

	if typeutils.IsZero(m.RevokedAt) { // not required
		return nil
	}

	if err := validate.FormatOf("revokedAt", "body", "date-time", m.RevokedAt.String(), formats); err != nil {
		return err
	}

	return nil
}

func (m *AuthorizedClient) validateRevokedByID(formats strfmt.Registry) error {

	if typeutils.IsZero(m.RevokedByID) { // not required
		return nil
	}

	if err := validate.FormatOf("revokedById", "body", "uuid", m.RevokedByID.String(), formats); err != nil {
		return err
	}

	return nil
}

func (m *AuthorizedClient) validateSoftwareID(formats strfmt.Registry) error {

	if typeutils.IsZero(m.SoftwareID) { // not required
		return nil
	}

	if err := validate.MaxLength("softwareId", "body", *m.SoftwareID, 255); err != nil {
		return err
	}

	return nil
}

func (m *AuthorizedClient) validateSoftwareVersion(formats strfmt.Registry) error {

	if typeutils.IsZero(m.SoftwareVersion) { // not required
		return nil
	}

	if err := validate.MaxLength("softwareVersion", "body", *m.SoftwareVersion, 80); err != nil {
		return err
	}

	return nil
}

var authorizedClientTypeStatusPropEnum []any

func init() {
	var res []string
	if err := json.Unmarshal([]byte(`["pending","active","revoked","expired"]`), &res); err != nil {
		panic(err)
	}
	for _, v := range res {
		authorizedClientTypeStatusPropEnum = append(authorizedClientTypeStatusPropEnum, v)
	}
}

// property enum
func (m *AuthorizedClient) validateStatusEnum(path, location string, value string) error {
	if err := validate.EnumCase(path, location, value, authorizedClientTypeStatusPropEnum, true); err != nil {
		return err
	}
	return nil
}

func (m *AuthorizedClient) validateStatus(formats strfmt.Registry) error {

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

	// value enum
	if err := m.validateStatusEnum("status", "body", *m.Status); err != nil {
		return err
	}

	return nil
}

func (m *AuthorizedClient) validateTenantID(formats strfmt.Registry) error {

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

	if err := validate.FormatOf("tenantId", "body", "uuid", m.TenantID.String(), formats); err != nil {
		return err
	}

	return nil
}

func (m *AuthorizedClient) validateUserID(formats strfmt.Registry) error {

	if typeutils.IsZero(m.UserID) { // not required
		return nil
	}

	if err := validate.FormatOf("userId", "body", "uuid", m.UserID.String(), formats); err != nil {
		return err
	}

	return nil
}

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

	// validation for a type composition with AuditFields
	if err := m.AuditFields.ContextValidate(ctx, formats); err != nil {
		res = append(res, err)
	}

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

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

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

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

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

func (m *AuthorizedClient) contextValidateApprovedAt(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "approvedAt", "body", m.ApprovedAt); err != nil {
		return err
	}

	return nil
}

func (m *AuthorizedClient) contextValidateLastUsedAt(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "lastUsedAt", "body", m.LastUsedAt); err != nil {
		return err
	}

	return nil
}

func (m *AuthorizedClient) contextValidateRevokedAt(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "revokedAt", "body", m.RevokedAt); err != nil {
		return err
	}

	return nil
}

func (m *AuthorizedClient) contextValidateRevokedByID(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "revokedById", "body", m.RevokedByID); err != nil {
		return err
	}

	return nil
}

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

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