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

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

// APIToken API token
//
// swagger:model APIToken
type APIToken struct {

	// The access Id associated with the API Tokens
	// Read Only: true
	AccessID string `json:"accessId,omitempty"`

	// The secret key associated with the API Tokens
	// Read Only: true
	AccessKey string `json:"accessKey,omitempty"`

	// The id of the user associated with the API Tokens
	// Read Only: true
	AdminID int32 `json:"adminId,omitempty"`

	// The name of the user associated with the API Tokens
	// Read Only: true
	AdminName string `json:"adminName,omitempty"`

	// The user who is the API Tokens created by
	// Read Only: true
	CreatedBy string `json:"createdBy,omitempty"`

	// The epoch at which the API Tokens were created
	// Read Only: true
	CreatedOn int64 `json:"createdOn,omitempty"`

	// The id of the API Token
	// Read Only: true
	ID int32 `json:"id,omitempty"`

	// The epoch at which the API Tokens were last used
	// Read Only: true
	LastUsedOn int64 `json:"lastUsedOn,omitempty"`

	// The note associated with the API Tokens
	// Example: John Doe's API Token
	Note string `json:"note,omitempty"`

	// The roles assigned to the user that is associated with the API Tokens
	// Read Only: true
	// Unique: true
	Roles []string `json:"roles,omitempty"`

	// 1 | 2 - Whether or not the API Tokens are enabled, where 2 = enabled
	// Example: 2
	Status int32 `json:"status,omitempty"`
}

// Validate validates this API token
func (m *APIToken) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *APIToken) validateRoles(formats strfmt.Registry) error {
	if swag.IsZero(m.Roles) { // not required
		return nil
	}

	if err := validate.UniqueItems("roles", "body", m.Roles); err != nil {
		return err
	}

	return nil
}

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

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

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

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

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

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

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

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

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

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

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

func (m *APIToken) contextValidateAccessID(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *APIToken) contextValidateAccessKey(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *APIToken) contextValidateAdminID(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *APIToken) contextValidateAdminName(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *APIToken) contextValidateCreatedBy(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *APIToken) contextValidateCreatedOn(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *APIToken) contextValidateID(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *APIToken) contextValidateLastUsedOn(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *APIToken) contextValidateRoles(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "roles", "body", []string(m.Roles)); err != nil {
		return err
	}

	return nil
}

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

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