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

// TenantMembershipCreate Exactly one of userId or email is required; Members validates the exclusive selector transactionally.
//
// swagger:model TenantMembershipCreate
type TenantMembershipCreate struct {

	// access level
	// Required: true
	// Enum: ["owner","manager","member","read_only"]
	AccessLevel *string `json:"accessLevel"`

	// email
	// Format: email
	Email *strfmt.Email `json:"email,omitempty"`

	// status
	// Enum: ["active","suspended","revoked"]
	Status *string `json:"status,omitempty"`

	// tenant Id
	// Required: true
	// Max Length: 36
	// Min Length: 1
	TenantID *string `json:"tenantId"`

	// user Id
	// Format: uuid
	UserID *strfmt.UUID `json:"userId,omitempty"`
}

// Validate validates this tenant membership create
func (m *TenantMembershipCreate) Validate(formats strfmt.Registry) error {
	var res []error

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

	if err := m.validateEmail(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
}

var tenantMembershipCreateTypeAccessLevelPropEnum []any

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

const (

	// TenantMembershipCreateAccessLevelOwner captures enum value "owner"
	TenantMembershipCreateAccessLevelOwner string = "owner"

	// TenantMembershipCreateAccessLevelManager captures enum value "manager"
	TenantMembershipCreateAccessLevelManager string = "manager"

	// TenantMembershipCreateAccessLevelMember captures enum value "member"
	TenantMembershipCreateAccessLevelMember string = "member"

	// TenantMembershipCreateAccessLevelReadOnly captures enum value "read_only"
	TenantMembershipCreateAccessLevelReadOnly string = "read_only"
)

// prop value enum
func (m *TenantMembershipCreate) validateAccessLevelEnum(path, location string, value string) error {
	if err := validate.EnumCase(path, location, value, tenantMembershipCreateTypeAccessLevelPropEnum, true); err != nil {
		return err
	}
	return nil
}

func (m *TenantMembershipCreate) validateAccessLevel(formats strfmt.Registry) error {

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

	// value enum
	if err := m.validateAccessLevelEnum("accessLevel", "body", *m.AccessLevel); err != nil {
		return err
	}

	return nil
}

func (m *TenantMembershipCreate) validateEmail(formats strfmt.Registry) error {
	if typeutils.IsZero(m.Email) { // not required
		return nil
	}

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

	return nil
}

var tenantMembershipCreateTypeStatusPropEnum []any

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

const (

	// TenantMembershipCreateStatusActive captures enum value "active"
	TenantMembershipCreateStatusActive string = "active"

	// TenantMembershipCreateStatusSuspended captures enum value "suspended"
	TenantMembershipCreateStatusSuspended string = "suspended"

	// TenantMembershipCreateStatusRevoked captures enum value "revoked"
	TenantMembershipCreateStatusRevoked string = "revoked"
)

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

func (m *TenantMembershipCreate) validateStatus(formats strfmt.Registry) error {
	if typeutils.IsZero(m.Status) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

	return nil
}

func (m *TenantMembershipCreate) 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 validates this tenant membership create based on context it is used
func (m *TenantMembershipCreate) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	return nil
}

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

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