// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"sync"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
	"github.com/member-gentei/member-gentei/gentei/ent/guild"
	"github.com/member-gentei/member-gentei/gentei/ent/guildrole"
	"github.com/member-gentei/member-gentei/gentei/ent/predicate"
	"github.com/member-gentei/member-gentei/gentei/ent/schema"
	"github.com/member-gentei/member-gentei/gentei/ent/user"
	"github.com/member-gentei/member-gentei/gentei/ent/usermembership"
	"github.com/member-gentei/member-gentei/gentei/ent/youtubetalent"
	"golang.org/x/oauth2"
)

const (
	// Operation types.
	OpCreate    = ent.OpCreate
	OpDelete    = ent.OpDelete
	OpDeleteOne = ent.OpDeleteOne
	OpUpdate    = ent.OpUpdate
	OpUpdateOne = ent.OpUpdateOne

	// Node types.
	TypeGuild          = "Guild"
	TypeGuildRole      = "GuildRole"
	TypeUser           = "User"
	TypeUserMembership = "UserMembership"
	TypeYouTubeTalent  = "YouTubeTalent"
)

// GuildMutation represents an operation that mutates the Guild nodes in the graph.
type GuildMutation struct {
	config
	op                         Op
	typ                        string
	id                         *uint64
	name                       *string
	icon_hash                  *string
	audit_channel              *uint64
	addaudit_channel           *int64
	language                   *guild.Language
	admin_snowflakes           *[]uint64
	appendadmin_snowflakes     []uint64
	moderator_snowflakes       *[]uint64
	appendmoderator_snowflakes []uint64
	settings                   **schema.GuildSettings
	clearedFields              map[string]struct{}
	members                    map[uint64]struct{}
	removedmembers             map[uint64]struct{}
	clearedmembers             bool
	admins                     map[uint64]struct{}
	removedadmins              map[uint64]struct{}
	clearedadmins              bool
	roles                      map[uint64]struct{}
	removedroles               map[uint64]struct{}
	clearedroles               bool
	youtube_talents            map[string]struct{}
	removedyoutube_talents     map[string]struct{}
	clearedyoutube_talents     bool
	done                       bool
	oldValue                   func(context.Context) (*Guild, error)
	predicates                 []predicate.Guild
}

var _ ent.Mutation = (*GuildMutation)(nil)

// guildOption allows management of the mutation configuration using functional options.
type guildOption func(*GuildMutation)

// newGuildMutation creates new mutation for the Guild entity.
func newGuildMutation(c config, op Op, opts ...guildOption) *GuildMutation {
	m := &GuildMutation{
		config:        c,
		op:            op,
		typ:           TypeGuild,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withGuildID sets the ID field of the mutation.
func withGuildID(id uint64) guildOption {
	return func(m *GuildMutation) {
		var (
			err   error
			once  sync.Once
			value *Guild
		)
		m.oldValue = func(ctx context.Context) (*Guild, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().Guild.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withGuild sets the old Guild of the mutation.
func withGuild(node *Guild) guildOption {
	return func(m *GuildMutation) {
		m.oldValue = func(context.Context) (*Guild, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}

// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m GuildMutation) Client() *Client {
	client := &Client{config: m.config}
	client.init()
	return client
}

// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m GuildMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of Guild entities.
func (m *GuildMutation) SetID(id uint64) {
	m.id = &id
}

// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *GuildMutation) ID() (id uint64, exists bool) {
	if m.id == nil {
		return
	}
	return *m.id, true
}

// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *GuildMutation) IDs(ctx context.Context) ([]uint64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []uint64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().Guild.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetName sets the "name" field.
func (m *GuildMutation) SetName(s string) {
	m.name = &s
}

// Name returns the value of the "name" field in the mutation.
func (m *GuildMutation) Name() (r string, exists bool) {
	v := m.name
	if v == nil {
		return
	}
	return *v, true
}

// OldName returns the old "name" field's value of the Guild entity.
// If the Guild object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GuildMutation) OldName(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldName is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldName requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldName: %w", err)
	}
	return oldValue.Name, nil
}

// ResetName resets all changes to the "name" field.
func (m *GuildMutation) ResetName() {
	m.name = nil
}

// SetIconHash sets the "icon_hash" field.
func (m *GuildMutation) SetIconHash(s string) {
	m.icon_hash = &s
}

// IconHash returns the value of the "icon_hash" field in the mutation.
func (m *GuildMutation) IconHash() (r string, exists bool) {
	v := m.icon_hash
	if v == nil {
		return
	}
	return *v, true
}

// OldIconHash returns the old "icon_hash" field's value of the Guild entity.
// If the Guild object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GuildMutation) OldIconHash(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldIconHash is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldIconHash requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldIconHash: %w", err)
	}
	return oldValue.IconHash, nil
}

// ClearIconHash clears the value of the "icon_hash" field.
func (m *GuildMutation) ClearIconHash() {
	m.icon_hash = nil
	m.clearedFields[guild.FieldIconHash] = struct{}{}
}

// IconHashCleared returns if the "icon_hash" field was cleared in this mutation.
func (m *GuildMutation) IconHashCleared() bool {
	_, ok := m.clearedFields[guild.FieldIconHash]
	return ok
}

// ResetIconHash resets all changes to the "icon_hash" field.
func (m *GuildMutation) ResetIconHash() {
	m.icon_hash = nil
	delete(m.clearedFields, guild.FieldIconHash)
}

// SetAuditChannel sets the "audit_channel" field.
func (m *GuildMutation) SetAuditChannel(u uint64) {
	m.audit_channel = &u
	m.addaudit_channel = nil
}

// AuditChannel returns the value of the "audit_channel" field in the mutation.
func (m *GuildMutation) AuditChannel() (r uint64, exists bool) {
	v := m.audit_channel
	if v == nil {
		return
	}
	return *v, true
}

// OldAuditChannel returns the old "audit_channel" field's value of the Guild entity.
// If the Guild object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GuildMutation) OldAuditChannel(ctx context.Context) (v uint64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldAuditChannel is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldAuditChannel requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldAuditChannel: %w", err)
	}
	return oldValue.AuditChannel, nil
}

// AddAuditChannel adds u to the "audit_channel" field.
func (m *GuildMutation) AddAuditChannel(u int64) {
	if m.addaudit_channel != nil {
		*m.addaudit_channel += u
	} else {
		m.addaudit_channel = &u
	}
}

// AddedAuditChannel returns the value that was added to the "audit_channel" field in this mutation.
func (m *GuildMutation) AddedAuditChannel() (r int64, exists bool) {
	v := m.addaudit_channel
	if v == nil {
		return
	}
	return *v, true
}

// ClearAuditChannel clears the value of the "audit_channel" field.
func (m *GuildMutation) ClearAuditChannel() {
	m.audit_channel = nil
	m.addaudit_channel = nil
	m.clearedFields[guild.FieldAuditChannel] = struct{}{}
}

// AuditChannelCleared returns if the "audit_channel" field was cleared in this mutation.
func (m *GuildMutation) AuditChannelCleared() bool {
	_, ok := m.clearedFields[guild.FieldAuditChannel]
	return ok
}

// ResetAuditChannel resets all changes to the "audit_channel" field.
func (m *GuildMutation) ResetAuditChannel() {
	m.audit_channel = nil
	m.addaudit_channel = nil
	delete(m.clearedFields, guild.FieldAuditChannel)
}

// SetLanguage sets the "language" field.
func (m *GuildMutation) SetLanguage(gu guild.Language) {
	m.language = &gu
}

// Language returns the value of the "language" field in the mutation.
func (m *GuildMutation) Language() (r guild.Language, exists bool) {
	v := m.language
	if v == nil {
		return
	}
	return *v, true
}

// OldLanguage returns the old "language" field's value of the Guild entity.
// If the Guild object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GuildMutation) OldLanguage(ctx context.Context) (v guild.Language, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldLanguage is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldLanguage requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldLanguage: %w", err)
	}
	return oldValue.Language, nil
}

// ResetLanguage resets all changes to the "language" field.
func (m *GuildMutation) ResetLanguage() {
	m.language = nil
}

// SetAdminSnowflakes sets the "admin_snowflakes" field.
func (m *GuildMutation) SetAdminSnowflakes(u []uint64) {
	m.admin_snowflakes = &u
	m.appendadmin_snowflakes = nil
}

// AdminSnowflakes returns the value of the "admin_snowflakes" field in the mutation.
func (m *GuildMutation) AdminSnowflakes() (r []uint64, exists bool) {
	v := m.admin_snowflakes
	if v == nil {
		return
	}
	return *v, true
}

// OldAdminSnowflakes returns the old "admin_snowflakes" field's value of the Guild entity.
// If the Guild object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GuildMutation) OldAdminSnowflakes(ctx context.Context) (v []uint64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldAdminSnowflakes is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldAdminSnowflakes requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldAdminSnowflakes: %w", err)
	}
	return oldValue.AdminSnowflakes, nil
}

// AppendAdminSnowflakes adds u to the "admin_snowflakes" field.
func (m *GuildMutation) AppendAdminSnowflakes(u []uint64) {
	m.appendadmin_snowflakes = append(m.appendadmin_snowflakes, u...)
}

// AppendedAdminSnowflakes returns the list of values that were appended to the "admin_snowflakes" field in this mutation.
func (m *GuildMutation) AppendedAdminSnowflakes() ([]uint64, bool) {
	if len(m.appendadmin_snowflakes) == 0 {
		return nil, false
	}
	return m.appendadmin_snowflakes, true
}

// ResetAdminSnowflakes resets all changes to the "admin_snowflakes" field.
func (m *GuildMutation) ResetAdminSnowflakes() {
	m.admin_snowflakes = nil
	m.appendadmin_snowflakes = nil
}

// SetModeratorSnowflakes sets the "moderator_snowflakes" field.
func (m *GuildMutation) SetModeratorSnowflakes(u []uint64) {
	m.moderator_snowflakes = &u
	m.appendmoderator_snowflakes = nil
}

// ModeratorSnowflakes returns the value of the "moderator_snowflakes" field in the mutation.
func (m *GuildMutation) ModeratorSnowflakes() (r []uint64, exists bool) {
	v := m.moderator_snowflakes
	if v == nil {
		return
	}
	return *v, true
}

// OldModeratorSnowflakes returns the old "moderator_snowflakes" field's value of the Guild entity.
// If the Guild object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GuildMutation) OldModeratorSnowflakes(ctx context.Context) (v []uint64, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldModeratorSnowflakes is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldModeratorSnowflakes requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldModeratorSnowflakes: %w", err)
	}
	return oldValue.ModeratorSnowflakes, nil
}

// AppendModeratorSnowflakes adds u to the "moderator_snowflakes" field.
func (m *GuildMutation) AppendModeratorSnowflakes(u []uint64) {
	m.appendmoderator_snowflakes = append(m.appendmoderator_snowflakes, u...)
}

// AppendedModeratorSnowflakes returns the list of values that were appended to the "moderator_snowflakes" field in this mutation.
func (m *GuildMutation) AppendedModeratorSnowflakes() ([]uint64, bool) {
	if len(m.appendmoderator_snowflakes) == 0 {
		return nil, false
	}
	return m.appendmoderator_snowflakes, true
}

// ClearModeratorSnowflakes clears the value of the "moderator_snowflakes" field.
func (m *GuildMutation) ClearModeratorSnowflakes() {
	m.moderator_snowflakes = nil
	m.appendmoderator_snowflakes = nil
	m.clearedFields[guild.FieldModeratorSnowflakes] = struct{}{}
}

// ModeratorSnowflakesCleared returns if the "moderator_snowflakes" field was cleared in this mutation.
func (m *GuildMutation) ModeratorSnowflakesCleared() bool {
	_, ok := m.clearedFields[guild.FieldModeratorSnowflakes]
	return ok
}

// ResetModeratorSnowflakes resets all changes to the "moderator_snowflakes" field.
func (m *GuildMutation) ResetModeratorSnowflakes() {
	m.moderator_snowflakes = nil
	m.appendmoderator_snowflakes = nil
	delete(m.clearedFields, guild.FieldModeratorSnowflakes)
}

// SetSettings sets the "settings" field.
func (m *GuildMutation) SetSettings(ss *schema.GuildSettings) {
	m.settings = &ss
}

// Settings returns the value of the "settings" field in the mutation.
func (m *GuildMutation) Settings() (r *schema.GuildSettings, exists bool) {
	v := m.settings
	if v == nil {
		return
	}
	return *v, true
}

// OldSettings returns the old "settings" field's value of the Guild entity.
// If the Guild object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GuildMutation) OldSettings(ctx context.Context) (v *schema.GuildSettings, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldSettings is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldSettings requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldSettings: %w", err)
	}
	return oldValue.Settings, nil
}

// ClearSettings clears the value of the "settings" field.
func (m *GuildMutation) ClearSettings() {
	m.settings = nil
	m.clearedFields[guild.FieldSettings] = struct{}{}
}

// SettingsCleared returns if the "settings" field was cleared in this mutation.
func (m *GuildMutation) SettingsCleared() bool {
	_, ok := m.clearedFields[guild.FieldSettings]
	return ok
}

// ResetSettings resets all changes to the "settings" field.
func (m *GuildMutation) ResetSettings() {
	m.settings = nil
	delete(m.clearedFields, guild.FieldSettings)
}

// AddMemberIDs adds the "members" edge to the User entity by ids.
func (m *GuildMutation) AddMemberIDs(ids ...uint64) {
	if m.members == nil {
		m.members = make(map[uint64]struct{})
	}
	for i := range ids {
		m.members[ids[i]] = struct{}{}
	}
}

// ClearMembers clears the "members" edge to the User entity.
func (m *GuildMutation) ClearMembers() {
	m.clearedmembers = true
}

// MembersCleared reports if the "members" edge to the User entity was cleared.
func (m *GuildMutation) MembersCleared() bool {
	return m.clearedmembers
}

// RemoveMemberIDs removes the "members" edge to the User entity by IDs.
func (m *GuildMutation) RemoveMemberIDs(ids ...uint64) {
	if m.removedmembers == nil {
		m.removedmembers = make(map[uint64]struct{})
	}
	for i := range ids {
		delete(m.members, ids[i])
		m.removedmembers[ids[i]] = struct{}{}
	}
}

// RemovedMembers returns the removed IDs of the "members" edge to the User entity.
func (m *GuildMutation) RemovedMembersIDs() (ids []uint64) {
	for id := range m.removedmembers {
		ids = append(ids, id)
	}
	return
}

// MembersIDs returns the "members" edge IDs in the mutation.
func (m *GuildMutation) MembersIDs() (ids []uint64) {
	for id := range m.members {
		ids = append(ids, id)
	}
	return
}

// ResetMembers resets all changes to the "members" edge.
func (m *GuildMutation) ResetMembers() {
	m.members = nil
	m.clearedmembers = false
	m.removedmembers = nil
}

// AddAdminIDs adds the "admins" edge to the User entity by ids.
func (m *GuildMutation) AddAdminIDs(ids ...uint64) {
	if m.admins == nil {
		m.admins = make(map[uint64]struct{})
	}
	for i := range ids {
		m.admins[ids[i]] = struct{}{}
	}
}

// ClearAdmins clears the "admins" edge to the User entity.
func (m *GuildMutation) ClearAdmins() {
	m.clearedadmins = true
}

// AdminsCleared reports if the "admins" edge to the User entity was cleared.
func (m *GuildMutation) AdminsCleared() bool {
	return m.clearedadmins
}

// RemoveAdminIDs removes the "admins" edge to the User entity by IDs.
func (m *GuildMutation) RemoveAdminIDs(ids ...uint64) {
	if m.removedadmins == nil {
		m.removedadmins = make(map[uint64]struct{})
	}
	for i := range ids {
		delete(m.admins, ids[i])
		m.removedadmins[ids[i]] = struct{}{}
	}
}

// RemovedAdmins returns the removed IDs of the "admins" edge to the User entity.
func (m *GuildMutation) RemovedAdminsIDs() (ids []uint64) {
	for id := range m.removedadmins {
		ids = append(ids, id)
	}
	return
}

// AdminsIDs returns the "admins" edge IDs in the mutation.
func (m *GuildMutation) AdminsIDs() (ids []uint64) {
	for id := range m.admins {
		ids = append(ids, id)
	}
	return
}

// ResetAdmins resets all changes to the "admins" edge.
func (m *GuildMutation) ResetAdmins() {
	m.admins = nil
	m.clearedadmins = false
	m.removedadmins = nil
}

// AddRoleIDs adds the "roles" edge to the GuildRole entity by ids.
func (m *GuildMutation) AddRoleIDs(ids ...uint64) {
	if m.roles == nil {
		m.roles = make(map[uint64]struct{})
	}
	for i := range ids {
		m.roles[ids[i]] = struct{}{}
	}
}

// ClearRoles clears the "roles" edge to the GuildRole entity.
func (m *GuildMutation) ClearRoles() {
	m.clearedroles = true
}

// RolesCleared reports if the "roles" edge to the GuildRole entity was cleared.
func (m *GuildMutation) RolesCleared() bool {
	return m.clearedroles
}

// RemoveRoleIDs removes the "roles" edge to the GuildRole entity by IDs.
func (m *GuildMutation) RemoveRoleIDs(ids ...uint64) {
	if m.removedroles == nil {
		m.removedroles = make(map[uint64]struct{})
	}
	for i := range ids {
		delete(m.roles, ids[i])
		m.removedroles[ids[i]] = struct{}{}
	}
}

// RemovedRoles returns the removed IDs of the "roles" edge to the GuildRole entity.
func (m *GuildMutation) RemovedRolesIDs() (ids []uint64) {
	for id := range m.removedroles {
		ids = append(ids, id)
	}
	return
}

// RolesIDs returns the "roles" edge IDs in the mutation.
func (m *GuildMutation) RolesIDs() (ids []uint64) {
	for id := range m.roles {
		ids = append(ids, id)
	}
	return
}

// ResetRoles resets all changes to the "roles" edge.
func (m *GuildMutation) ResetRoles() {
	m.roles = nil
	m.clearedroles = false
	m.removedroles = nil
}

// AddYoutubeTalentIDs adds the "youtube_talents" edge to the YouTubeTalent entity by ids.
func (m *GuildMutation) AddYoutubeTalentIDs(ids ...string) {
	if m.youtube_talents == nil {
		m.youtube_talents = make(map[string]struct{})
	}
	for i := range ids {
		m.youtube_talents[ids[i]] = struct{}{}
	}
}

// ClearYoutubeTalents clears the "youtube_talents" edge to the YouTubeTalent entity.
func (m *GuildMutation) ClearYoutubeTalents() {
	m.clearedyoutube_talents = true
}

// YoutubeTalentsCleared reports if the "youtube_talents" edge to the YouTubeTalent entity was cleared.
func (m *GuildMutation) YoutubeTalentsCleared() bool {
	return m.clearedyoutube_talents
}

// RemoveYoutubeTalentIDs removes the "youtube_talents" edge to the YouTubeTalent entity by IDs.
func (m *GuildMutation) RemoveYoutubeTalentIDs(ids ...string) {
	if m.removedyoutube_talents == nil {
		m.removedyoutube_talents = make(map[string]struct{})
	}
	for i := range ids {
		delete(m.youtube_talents, ids[i])
		m.removedyoutube_talents[ids[i]] = struct{}{}
	}
}

// RemovedYoutubeTalents returns the removed IDs of the "youtube_talents" edge to the YouTubeTalent entity.
func (m *GuildMutation) RemovedYoutubeTalentsIDs() (ids []string) {
	for id := range m.removedyoutube_talents {
		ids = append(ids, id)
	}
	return
}

// YoutubeTalentsIDs returns the "youtube_talents" edge IDs in the mutation.
func (m *GuildMutation) YoutubeTalentsIDs() (ids []string) {
	for id := range m.youtube_talents {
		ids = append(ids, id)
	}
	return
}

// ResetYoutubeTalents resets all changes to the "youtube_talents" edge.
func (m *GuildMutation) ResetYoutubeTalents() {
	m.youtube_talents = nil
	m.clearedyoutube_talents = false
	m.removedyoutube_talents = nil
}

// Where appends a list predicates to the GuildMutation builder.
func (m *GuildMutation) Where(ps ...predicate.Guild) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the GuildMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *GuildMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.Guild, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *GuildMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *GuildMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (Guild).
func (m *GuildMutation) Type() string {
	return m.typ
}

// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *GuildMutation) Fields() []string {
	fields := make([]string, 0, 7)
	if m.name != nil {
		fields = append(fields, guild.FieldName)
	}
	if m.icon_hash != nil {
		fields = append(fields, guild.FieldIconHash)
	}
	if m.audit_channel != nil {
		fields = append(fields, guild.FieldAuditChannel)
	}
	if m.language != nil {
		fields = append(fields, guild.FieldLanguage)
	}
	if m.admin_snowflakes != nil {
		fields = append(fields, guild.FieldAdminSnowflakes)
	}
	if m.moderator_snowflakes != nil {
		fields = append(fields, guild.FieldModeratorSnowflakes)
	}
	if m.settings != nil {
		fields = append(fields, guild.FieldSettings)
	}
	return fields
}

// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *GuildMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case guild.FieldName:
		return m.Name()
	case guild.FieldIconHash:
		return m.IconHash()
	case guild.FieldAuditChannel:
		return m.AuditChannel()
	case guild.FieldLanguage:
		return m.Language()
	case guild.FieldAdminSnowflakes:
		return m.AdminSnowflakes()
	case guild.FieldModeratorSnowflakes:
		return m.ModeratorSnowflakes()
	case guild.FieldSettings:
		return m.Settings()
	}
	return nil, false
}

// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *GuildMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case guild.FieldName:
		return m.OldName(ctx)
	case guild.FieldIconHash:
		return m.OldIconHash(ctx)
	case guild.FieldAuditChannel:
		return m.OldAuditChannel(ctx)
	case guild.FieldLanguage:
		return m.OldLanguage(ctx)
	case guild.FieldAdminSnowflakes:
		return m.OldAdminSnowflakes(ctx)
	case guild.FieldModeratorSnowflakes:
		return m.OldModeratorSnowflakes(ctx)
	case guild.FieldSettings:
		return m.OldSettings(ctx)
	}
	return nil, fmt.Errorf("unknown Guild field %s", name)
}

// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *GuildMutation) SetField(name string, value ent.Value) error {
	switch name {
	case guild.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case guild.FieldIconHash:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetIconHash(v)
		return nil
	case guild.FieldAuditChannel:
		v, ok := value.(uint64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAuditChannel(v)
		return nil
	case guild.FieldLanguage:
		v, ok := value.(guild.Language)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLanguage(v)
		return nil
	case guild.FieldAdminSnowflakes:
		v, ok := value.([]uint64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAdminSnowflakes(v)
		return nil
	case guild.FieldModeratorSnowflakes:
		v, ok := value.([]uint64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetModeratorSnowflakes(v)
		return nil
	case guild.FieldSettings:
		v, ok := value.(*schema.GuildSettings)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetSettings(v)
		return nil
	}
	return fmt.Errorf("unknown Guild field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *GuildMutation) AddedFields() []string {
	var fields []string
	if m.addaudit_channel != nil {
		fields = append(fields, guild.FieldAuditChannel)
	}
	return fields
}

// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *GuildMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case guild.FieldAuditChannel:
		return m.AddedAuditChannel()
	}
	return nil, false
}

// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *GuildMutation) AddField(name string, value ent.Value) error {
	switch name {
	case guild.FieldAuditChannel:
		v, ok := value.(int64)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddAuditChannel(v)
		return nil
	}
	return fmt.Errorf("unknown Guild numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *GuildMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(guild.FieldIconHash) {
		fields = append(fields, guild.FieldIconHash)
	}
	if m.FieldCleared(guild.FieldAuditChannel) {
		fields = append(fields, guild.FieldAuditChannel)
	}
	if m.FieldCleared(guild.FieldModeratorSnowflakes) {
		fields = append(fields, guild.FieldModeratorSnowflakes)
	}
	if m.FieldCleared(guild.FieldSettings) {
		fields = append(fields, guild.FieldSettings)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *GuildMutation) FieldCleared(name string) bool {
	_, ok := m.clearedFields[name]
	return ok
}

// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *GuildMutation) ClearField(name string) error {
	switch name {
	case guild.FieldIconHash:
		m.ClearIconHash()
		return nil
	case guild.FieldAuditChannel:
		m.ClearAuditChannel()
		return nil
	case guild.FieldModeratorSnowflakes:
		m.ClearModeratorSnowflakes()
		return nil
	case guild.FieldSettings:
		m.ClearSettings()
		return nil
	}
	return fmt.Errorf("unknown Guild nullable field %s", name)
}

// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *GuildMutation) ResetField(name string) error {
	switch name {
	case guild.FieldName:
		m.ResetName()
		return nil
	case guild.FieldIconHash:
		m.ResetIconHash()
		return nil
	case guild.FieldAuditChannel:
		m.ResetAuditChannel()
		return nil
	case guild.FieldLanguage:
		m.ResetLanguage()
		return nil
	case guild.FieldAdminSnowflakes:
		m.ResetAdminSnowflakes()
		return nil
	case guild.FieldModeratorSnowflakes:
		m.ResetModeratorSnowflakes()
		return nil
	case guild.FieldSettings:
		m.ResetSettings()
		return nil
	}
	return fmt.Errorf("unknown Guild field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *GuildMutation) AddedEdges() []string {
	edges := make([]string, 0, 4)
	if m.members != nil {
		edges = append(edges, guild.EdgeMembers)
	}
	if m.admins != nil {
		edges = append(edges, guild.EdgeAdmins)
	}
	if m.roles != nil {
		edges = append(edges, guild.EdgeRoles)
	}
	if m.youtube_talents != nil {
		edges = append(edges, guild.EdgeYoutubeTalents)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *GuildMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case guild.EdgeMembers:
		ids := make([]ent.Value, 0, len(m.members))
		for id := range m.members {
			ids = append(ids, id)
		}
		return ids
	case guild.EdgeAdmins:
		ids := make([]ent.Value, 0, len(m.admins))
		for id := range m.admins {
			ids = append(ids, id)
		}
		return ids
	case guild.EdgeRoles:
		ids := make([]ent.Value, 0, len(m.roles))
		for id := range m.roles {
			ids = append(ids, id)
		}
		return ids
	case guild.EdgeYoutubeTalents:
		ids := make([]ent.Value, 0, len(m.youtube_talents))
		for id := range m.youtube_talents {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *GuildMutation) RemovedEdges() []string {
	edges := make([]string, 0, 4)
	if m.removedmembers != nil {
		edges = append(edges, guild.EdgeMembers)
	}
	if m.removedadmins != nil {
		edges = append(edges, guild.EdgeAdmins)
	}
	if m.removedroles != nil {
		edges = append(edges, guild.EdgeRoles)
	}
	if m.removedyoutube_talents != nil {
		edges = append(edges, guild.EdgeYoutubeTalents)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *GuildMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case guild.EdgeMembers:
		ids := make([]ent.Value, 0, len(m.removedmembers))
		for id := range m.removedmembers {
			ids = append(ids, id)
		}
		return ids
	case guild.EdgeAdmins:
		ids := make([]ent.Value, 0, len(m.removedadmins))
		for id := range m.removedadmins {
			ids = append(ids, id)
		}
		return ids
	case guild.EdgeRoles:
		ids := make([]ent.Value, 0, len(m.removedroles))
		for id := range m.removedroles {
			ids = append(ids, id)
		}
		return ids
	case guild.EdgeYoutubeTalents:
		ids := make([]ent.Value, 0, len(m.removedyoutube_talents))
		for id := range m.removedyoutube_talents {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *GuildMutation) ClearedEdges() []string {
	edges := make([]string, 0, 4)
	if m.clearedmembers {
		edges = append(edges, guild.EdgeMembers)
	}
	if m.clearedadmins {
		edges = append(edges, guild.EdgeAdmins)
	}
	if m.clearedroles {
		edges = append(edges, guild.EdgeRoles)
	}
	if m.clearedyoutube_talents {
		edges = append(edges, guild.EdgeYoutubeTalents)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *GuildMutation) EdgeCleared(name string) bool {
	switch name {
	case guild.EdgeMembers:
		return m.clearedmembers
	case guild.EdgeAdmins:
		return m.clearedadmins
	case guild.EdgeRoles:
		return m.clearedroles
	case guild.EdgeYoutubeTalents:
		return m.clearedyoutube_talents
	}
	return false
}

// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *GuildMutation) ClearEdge(name string) error {
	switch name {
	}
	return fmt.Errorf("unknown Guild unique edge %s", name)
}

// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *GuildMutation) ResetEdge(name string) error {
	switch name {
	case guild.EdgeMembers:
		m.ResetMembers()
		return nil
	case guild.EdgeAdmins:
		m.ResetAdmins()
		return nil
	case guild.EdgeRoles:
		m.ResetRoles()
		return nil
	case guild.EdgeYoutubeTalents:
		m.ResetYoutubeTalents()
		return nil
	}
	return fmt.Errorf("unknown Guild edge %s", name)
}

// GuildRoleMutation represents an operation that mutates the GuildRole nodes in the graph.
type GuildRoleMutation struct {
	config
	op                      Op
	typ                     string
	id                      *uint64
	name                    *string
	last_updated            *time.Time
	clearedFields           map[string]struct{}
	guild                   *uint64
	clearedguild            bool
	user_memberships        map[int]struct{}
	removeduser_memberships map[int]struct{}
	cleareduser_memberships bool
	talent                  *string
	clearedtalent           bool
	done                    bool
	oldValue                func(context.Context) (*GuildRole, error)
	predicates              []predicate.GuildRole
}

var _ ent.Mutation = (*GuildRoleMutation)(nil)

// guildroleOption allows management of the mutation configuration using functional options.
type guildroleOption func(*GuildRoleMutation)

// newGuildRoleMutation creates new mutation for the GuildRole entity.
func newGuildRoleMutation(c config, op Op, opts ...guildroleOption) *GuildRoleMutation {
	m := &GuildRoleMutation{
		config:        c,
		op:            op,
		typ:           TypeGuildRole,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withGuildRoleID sets the ID field of the mutation.
func withGuildRoleID(id uint64) guildroleOption {
	return func(m *GuildRoleMutation) {
		var (
			err   error
			once  sync.Once
			value *GuildRole
		)
		m.oldValue = func(ctx context.Context) (*GuildRole, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().GuildRole.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withGuildRole sets the old GuildRole of the mutation.
func withGuildRole(node *GuildRole) guildroleOption {
	return func(m *GuildRoleMutation) {
		m.oldValue = func(context.Context) (*GuildRole, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}

// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m GuildRoleMutation) Client() *Client {
	client := &Client{config: m.config}
	client.init()
	return client
}

// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m GuildRoleMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of GuildRole entities.
func (m *GuildRoleMutation) SetID(id uint64) {
	m.id = &id
}

// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *GuildRoleMutation) ID() (id uint64, exists bool) {
	if m.id == nil {
		return
	}
	return *m.id, true
}

// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *GuildRoleMutation) IDs(ctx context.Context) ([]uint64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []uint64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().GuildRole.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetName sets the "name" field.
func (m *GuildRoleMutation) SetName(s string) {
	m.name = &s
}

// Name returns the value of the "name" field in the mutation.
func (m *GuildRoleMutation) Name() (r string, exists bool) {
	v := m.name
	if v == nil {
		return
	}
	return *v, true
}

// OldName returns the old "name" field's value of the GuildRole entity.
// If the GuildRole object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GuildRoleMutation) OldName(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldName is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldName requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldName: %w", err)
	}
	return oldValue.Name, nil
}

// ResetName resets all changes to the "name" field.
func (m *GuildRoleMutation) ResetName() {
	m.name = nil
}

// SetLastUpdated sets the "last_updated" field.
func (m *GuildRoleMutation) SetLastUpdated(t time.Time) {
	m.last_updated = &t
}

// LastUpdated returns the value of the "last_updated" field in the mutation.
func (m *GuildRoleMutation) LastUpdated() (r time.Time, exists bool) {
	v := m.last_updated
	if v == nil {
		return
	}
	return *v, true
}

// OldLastUpdated returns the old "last_updated" field's value of the GuildRole entity.
// If the GuildRole object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *GuildRoleMutation) OldLastUpdated(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldLastUpdated is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldLastUpdated requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldLastUpdated: %w", err)
	}
	return oldValue.LastUpdated, nil
}

// ResetLastUpdated resets all changes to the "last_updated" field.
func (m *GuildRoleMutation) ResetLastUpdated() {
	m.last_updated = nil
}

// SetGuildID sets the "guild" edge to the Guild entity by id.
func (m *GuildRoleMutation) SetGuildID(id uint64) {
	m.guild = &id
}

// ClearGuild clears the "guild" edge to the Guild entity.
func (m *GuildRoleMutation) ClearGuild() {
	m.clearedguild = true
}

// GuildCleared reports if the "guild" edge to the Guild entity was cleared.
func (m *GuildRoleMutation) GuildCleared() bool {
	return m.clearedguild
}

// GuildID returns the "guild" edge ID in the mutation.
func (m *GuildRoleMutation) GuildID() (id uint64, exists bool) {
	if m.guild != nil {
		return *m.guild, true
	}
	return
}

// GuildIDs returns the "guild" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// GuildID instead. It exists only for internal usage by the builders.
func (m *GuildRoleMutation) GuildIDs() (ids []uint64) {
	if id := m.guild; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetGuild resets all changes to the "guild" edge.
func (m *GuildRoleMutation) ResetGuild() {
	m.guild = nil
	m.clearedguild = false
}

// AddUserMembershipIDs adds the "user_memberships" edge to the UserMembership entity by ids.
func (m *GuildRoleMutation) AddUserMembershipIDs(ids ...int) {
	if m.user_memberships == nil {
		m.user_memberships = make(map[int]struct{})
	}
	for i := range ids {
		m.user_memberships[ids[i]] = struct{}{}
	}
}

// ClearUserMemberships clears the "user_memberships" edge to the UserMembership entity.
func (m *GuildRoleMutation) ClearUserMemberships() {
	m.cleareduser_memberships = true
}

// UserMembershipsCleared reports if the "user_memberships" edge to the UserMembership entity was cleared.
func (m *GuildRoleMutation) UserMembershipsCleared() bool {
	return m.cleareduser_memberships
}

// RemoveUserMembershipIDs removes the "user_memberships" edge to the UserMembership entity by IDs.
func (m *GuildRoleMutation) RemoveUserMembershipIDs(ids ...int) {
	if m.removeduser_memberships == nil {
		m.removeduser_memberships = make(map[int]struct{})
	}
	for i := range ids {
		delete(m.user_memberships, ids[i])
		m.removeduser_memberships[ids[i]] = struct{}{}
	}
}

// RemovedUserMemberships returns the removed IDs of the "user_memberships" edge to the UserMembership entity.
func (m *GuildRoleMutation) RemovedUserMembershipsIDs() (ids []int) {
	for id := range m.removeduser_memberships {
		ids = append(ids, id)
	}
	return
}

// UserMembershipsIDs returns the "user_memberships" edge IDs in the mutation.
func (m *GuildRoleMutation) UserMembershipsIDs() (ids []int) {
	for id := range m.user_memberships {
		ids = append(ids, id)
	}
	return
}

// ResetUserMemberships resets all changes to the "user_memberships" edge.
func (m *GuildRoleMutation) ResetUserMemberships() {
	m.user_memberships = nil
	m.cleareduser_memberships = false
	m.removeduser_memberships = nil
}

// SetTalentID sets the "talent" edge to the YouTubeTalent entity by id.
func (m *GuildRoleMutation) SetTalentID(id string) {
	m.talent = &id
}

// ClearTalent clears the "talent" edge to the YouTubeTalent entity.
func (m *GuildRoleMutation) ClearTalent() {
	m.clearedtalent = true
}

// TalentCleared reports if the "talent" edge to the YouTubeTalent entity was cleared.
func (m *GuildRoleMutation) TalentCleared() bool {
	return m.clearedtalent
}

// TalentID returns the "talent" edge ID in the mutation.
func (m *GuildRoleMutation) TalentID() (id string, exists bool) {
	if m.talent != nil {
		return *m.talent, true
	}
	return
}

// TalentIDs returns the "talent" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// TalentID instead. It exists only for internal usage by the builders.
func (m *GuildRoleMutation) TalentIDs() (ids []string) {
	if id := m.talent; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetTalent resets all changes to the "talent" edge.
func (m *GuildRoleMutation) ResetTalent() {
	m.talent = nil
	m.clearedtalent = false
}

// Where appends a list predicates to the GuildRoleMutation builder.
func (m *GuildRoleMutation) Where(ps ...predicate.GuildRole) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the GuildRoleMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *GuildRoleMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.GuildRole, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *GuildRoleMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *GuildRoleMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (GuildRole).
func (m *GuildRoleMutation) Type() string {
	return m.typ
}

// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *GuildRoleMutation) Fields() []string {
	fields := make([]string, 0, 2)
	if m.name != nil {
		fields = append(fields, guildrole.FieldName)
	}
	if m.last_updated != nil {
		fields = append(fields, guildrole.FieldLastUpdated)
	}
	return fields
}

// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *GuildRoleMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case guildrole.FieldName:
		return m.Name()
	case guildrole.FieldLastUpdated:
		return m.LastUpdated()
	}
	return nil, false
}

// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *GuildRoleMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case guildrole.FieldName:
		return m.OldName(ctx)
	case guildrole.FieldLastUpdated:
		return m.OldLastUpdated(ctx)
	}
	return nil, fmt.Errorf("unknown GuildRole field %s", name)
}

// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *GuildRoleMutation) SetField(name string, value ent.Value) error {
	switch name {
	case guildrole.FieldName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetName(v)
		return nil
	case guildrole.FieldLastUpdated:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLastUpdated(v)
		return nil
	}
	return fmt.Errorf("unknown GuildRole field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *GuildRoleMutation) AddedFields() []string {
	return nil
}

// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *GuildRoleMutation) AddedField(name string) (ent.Value, bool) {
	return nil, false
}

// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *GuildRoleMutation) AddField(name string, value ent.Value) error {
	switch name {
	}
	return fmt.Errorf("unknown GuildRole numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *GuildRoleMutation) ClearedFields() []string {
	return nil
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *GuildRoleMutation) FieldCleared(name string) bool {
	_, ok := m.clearedFields[name]
	return ok
}

// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *GuildRoleMutation) ClearField(name string) error {
	return fmt.Errorf("unknown GuildRole nullable field %s", name)
}

// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *GuildRoleMutation) ResetField(name string) error {
	switch name {
	case guildrole.FieldName:
		m.ResetName()
		return nil
	case guildrole.FieldLastUpdated:
		m.ResetLastUpdated()
		return nil
	}
	return fmt.Errorf("unknown GuildRole field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *GuildRoleMutation) AddedEdges() []string {
	edges := make([]string, 0, 3)
	if m.guild != nil {
		edges = append(edges, guildrole.EdgeGuild)
	}
	if m.user_memberships != nil {
		edges = append(edges, guildrole.EdgeUserMemberships)
	}
	if m.talent != nil {
		edges = append(edges, guildrole.EdgeTalent)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *GuildRoleMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case guildrole.EdgeGuild:
		if id := m.guild; id != nil {
			return []ent.Value{*id}
		}
	case guildrole.EdgeUserMemberships:
		ids := make([]ent.Value, 0, len(m.user_memberships))
		for id := range m.user_memberships {
			ids = append(ids, id)
		}
		return ids
	case guildrole.EdgeTalent:
		if id := m.talent; id != nil {
			return []ent.Value{*id}
		}
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *GuildRoleMutation) RemovedEdges() []string {
	edges := make([]string, 0, 3)
	if m.removeduser_memberships != nil {
		edges = append(edges, guildrole.EdgeUserMemberships)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *GuildRoleMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case guildrole.EdgeUserMemberships:
		ids := make([]ent.Value, 0, len(m.removeduser_memberships))
		for id := range m.removeduser_memberships {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *GuildRoleMutation) ClearedEdges() []string {
	edges := make([]string, 0, 3)
	if m.clearedguild {
		edges = append(edges, guildrole.EdgeGuild)
	}
	if m.cleareduser_memberships {
		edges = append(edges, guildrole.EdgeUserMemberships)
	}
	if m.clearedtalent {
		edges = append(edges, guildrole.EdgeTalent)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *GuildRoleMutation) EdgeCleared(name string) bool {
	switch name {
	case guildrole.EdgeGuild:
		return m.clearedguild
	case guildrole.EdgeUserMemberships:
		return m.cleareduser_memberships
	case guildrole.EdgeTalent:
		return m.clearedtalent
	}
	return false
}

// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *GuildRoleMutation) ClearEdge(name string) error {
	switch name {
	case guildrole.EdgeGuild:
		m.ClearGuild()
		return nil
	case guildrole.EdgeTalent:
		m.ClearTalent()
		return nil
	}
	return fmt.Errorf("unknown GuildRole unique edge %s", name)
}

// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *GuildRoleMutation) ResetEdge(name string) error {
	switch name {
	case guildrole.EdgeGuild:
		m.ResetGuild()
		return nil
	case guildrole.EdgeUserMemberships:
		m.ResetUserMemberships()
		return nil
	case guildrole.EdgeTalent:
		m.ResetTalent()
		return nil
	}
	return fmt.Errorf("unknown GuildRole edge %s", name)
}

// UserMutation represents an operation that mutates the User nodes in the graph.
type UserMutation struct {
	config
	op                  Op
	typ                 string
	id                  *uint64
	full_name           *string
	avatar_hash         *string
	last_check          *time.Time
	youtube_id          *string
	youtube_token       **oauth2.Token
	discord_token       **oauth2.Token
	clearedFields       map[string]struct{}
	guilds              map[uint64]struct{}
	removedguilds       map[uint64]struct{}
	clearedguilds       bool
	guilds_admin        map[uint64]struct{}
	removedguilds_admin map[uint64]struct{}
	clearedguilds_admin bool
	memberships         map[int]struct{}
	removedmemberships  map[int]struct{}
	clearedmemberships  bool
	done                bool
	oldValue            func(context.Context) (*User, error)
	predicates          []predicate.User
}

var _ ent.Mutation = (*UserMutation)(nil)

// userOption allows management of the mutation configuration using functional options.
type userOption func(*UserMutation)

// newUserMutation creates new mutation for the User entity.
func newUserMutation(c config, op Op, opts ...userOption) *UserMutation {
	m := &UserMutation{
		config:        c,
		op:            op,
		typ:           TypeUser,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withUserID sets the ID field of the mutation.
func withUserID(id uint64) userOption {
	return func(m *UserMutation) {
		var (
			err   error
			once  sync.Once
			value *User
		)
		m.oldValue = func(ctx context.Context) (*User, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().User.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withUser sets the old User of the mutation.
func withUser(node *User) userOption {
	return func(m *UserMutation) {
		m.oldValue = func(context.Context) (*User, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}

// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m UserMutation) Client() *Client {
	client := &Client{config: m.config}
	client.init()
	return client
}

// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m UserMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of User entities.
func (m *UserMutation) SetID(id uint64) {
	m.id = &id
}

// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *UserMutation) ID() (id uint64, exists bool) {
	if m.id == nil {
		return
	}
	return *m.id, true
}

// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *UserMutation) IDs(ctx context.Context) ([]uint64, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []uint64{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().User.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetFullName sets the "full_name" field.
func (m *UserMutation) SetFullName(s string) {
	m.full_name = &s
}

// FullName returns the value of the "full_name" field in the mutation.
func (m *UserMutation) FullName() (r string, exists bool) {
	v := m.full_name
	if v == nil {
		return
	}
	return *v, true
}

// OldFullName returns the old "full_name" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldFullName(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldFullName is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldFullName requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldFullName: %w", err)
	}
	return oldValue.FullName, nil
}

// ResetFullName resets all changes to the "full_name" field.
func (m *UserMutation) ResetFullName() {
	m.full_name = nil
}

// SetAvatarHash sets the "avatar_hash" field.
func (m *UserMutation) SetAvatarHash(s string) {
	m.avatar_hash = &s
}

// AvatarHash returns the value of the "avatar_hash" field in the mutation.
func (m *UserMutation) AvatarHash() (r string, exists bool) {
	v := m.avatar_hash
	if v == nil {
		return
	}
	return *v, true
}

// OldAvatarHash returns the old "avatar_hash" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldAvatarHash(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldAvatarHash is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldAvatarHash requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldAvatarHash: %w", err)
	}
	return oldValue.AvatarHash, nil
}

// ResetAvatarHash resets all changes to the "avatar_hash" field.
func (m *UserMutation) ResetAvatarHash() {
	m.avatar_hash = nil
}

// SetLastCheck sets the "last_check" field.
func (m *UserMutation) SetLastCheck(t time.Time) {
	m.last_check = &t
}

// LastCheck returns the value of the "last_check" field in the mutation.
func (m *UserMutation) LastCheck() (r time.Time, exists bool) {
	v := m.last_check
	if v == nil {
		return
	}
	return *v, true
}

// OldLastCheck returns the old "last_check" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldLastCheck(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldLastCheck is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldLastCheck requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldLastCheck: %w", err)
	}
	return oldValue.LastCheck, nil
}

// ResetLastCheck resets all changes to the "last_check" field.
func (m *UserMutation) ResetLastCheck() {
	m.last_check = nil
}

// SetYoutubeID sets the "youtube_id" field.
func (m *UserMutation) SetYoutubeID(s string) {
	m.youtube_id = &s
}

// YoutubeID returns the value of the "youtube_id" field in the mutation.
func (m *UserMutation) YoutubeID() (r string, exists bool) {
	v := m.youtube_id
	if v == nil {
		return
	}
	return *v, true
}

// OldYoutubeID returns the old "youtube_id" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldYoutubeID(ctx context.Context) (v *string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldYoutubeID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldYoutubeID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldYoutubeID: %w", err)
	}
	return oldValue.YoutubeID, nil
}

// ClearYoutubeID clears the value of the "youtube_id" field.
func (m *UserMutation) ClearYoutubeID() {
	m.youtube_id = nil
	m.clearedFields[user.FieldYoutubeID] = struct{}{}
}

// YoutubeIDCleared returns if the "youtube_id" field was cleared in this mutation.
func (m *UserMutation) YoutubeIDCleared() bool {
	_, ok := m.clearedFields[user.FieldYoutubeID]
	return ok
}

// ResetYoutubeID resets all changes to the "youtube_id" field.
func (m *UserMutation) ResetYoutubeID() {
	m.youtube_id = nil
	delete(m.clearedFields, user.FieldYoutubeID)
}

// SetYoutubeToken sets the "youtube_token" field.
func (m *UserMutation) SetYoutubeToken(o *oauth2.Token) {
	m.youtube_token = &o
}

// YoutubeToken returns the value of the "youtube_token" field in the mutation.
func (m *UserMutation) YoutubeToken() (r *oauth2.Token, exists bool) {
	v := m.youtube_token
	if v == nil {
		return
	}
	return *v, true
}

// OldYoutubeToken returns the old "youtube_token" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldYoutubeToken(ctx context.Context) (v *oauth2.Token, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldYoutubeToken is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldYoutubeToken requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldYoutubeToken: %w", err)
	}
	return oldValue.YoutubeToken, nil
}

// ClearYoutubeToken clears the value of the "youtube_token" field.
func (m *UserMutation) ClearYoutubeToken() {
	m.youtube_token = nil
	m.clearedFields[user.FieldYoutubeToken] = struct{}{}
}

// YoutubeTokenCleared returns if the "youtube_token" field was cleared in this mutation.
func (m *UserMutation) YoutubeTokenCleared() bool {
	_, ok := m.clearedFields[user.FieldYoutubeToken]
	return ok
}

// ResetYoutubeToken resets all changes to the "youtube_token" field.
func (m *UserMutation) ResetYoutubeToken() {
	m.youtube_token = nil
	delete(m.clearedFields, user.FieldYoutubeToken)
}

// SetDiscordToken sets the "discord_token" field.
func (m *UserMutation) SetDiscordToken(o *oauth2.Token) {
	m.discord_token = &o
}

// DiscordToken returns the value of the "discord_token" field in the mutation.
func (m *UserMutation) DiscordToken() (r *oauth2.Token, exists bool) {
	v := m.discord_token
	if v == nil {
		return
	}
	return *v, true
}

// OldDiscordToken returns the old "discord_token" field's value of the User entity.
// If the User object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMutation) OldDiscordToken(ctx context.Context) (v *oauth2.Token, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldDiscordToken is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldDiscordToken requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldDiscordToken: %w", err)
	}
	return oldValue.DiscordToken, nil
}

// ClearDiscordToken clears the value of the "discord_token" field.
func (m *UserMutation) ClearDiscordToken() {
	m.discord_token = nil
	m.clearedFields[user.FieldDiscordToken] = struct{}{}
}

// DiscordTokenCleared returns if the "discord_token" field was cleared in this mutation.
func (m *UserMutation) DiscordTokenCleared() bool {
	_, ok := m.clearedFields[user.FieldDiscordToken]
	return ok
}

// ResetDiscordToken resets all changes to the "discord_token" field.
func (m *UserMutation) ResetDiscordToken() {
	m.discord_token = nil
	delete(m.clearedFields, user.FieldDiscordToken)
}

// AddGuildIDs adds the "guilds" edge to the Guild entity by ids.
func (m *UserMutation) AddGuildIDs(ids ...uint64) {
	if m.guilds == nil {
		m.guilds = make(map[uint64]struct{})
	}
	for i := range ids {
		m.guilds[ids[i]] = struct{}{}
	}
}

// ClearGuilds clears the "guilds" edge to the Guild entity.
func (m *UserMutation) ClearGuilds() {
	m.clearedguilds = true
}

// GuildsCleared reports if the "guilds" edge to the Guild entity was cleared.
func (m *UserMutation) GuildsCleared() bool {
	return m.clearedguilds
}

// RemoveGuildIDs removes the "guilds" edge to the Guild entity by IDs.
func (m *UserMutation) RemoveGuildIDs(ids ...uint64) {
	if m.removedguilds == nil {
		m.removedguilds = make(map[uint64]struct{})
	}
	for i := range ids {
		delete(m.guilds, ids[i])
		m.removedguilds[ids[i]] = struct{}{}
	}
}

// RemovedGuilds returns the removed IDs of the "guilds" edge to the Guild entity.
func (m *UserMutation) RemovedGuildsIDs() (ids []uint64) {
	for id := range m.removedguilds {
		ids = append(ids, id)
	}
	return
}

// GuildsIDs returns the "guilds" edge IDs in the mutation.
func (m *UserMutation) GuildsIDs() (ids []uint64) {
	for id := range m.guilds {
		ids = append(ids, id)
	}
	return
}

// ResetGuilds resets all changes to the "guilds" edge.
func (m *UserMutation) ResetGuilds() {
	m.guilds = nil
	m.clearedguilds = false
	m.removedguilds = nil
}

// AddGuildsAdminIDs adds the "guilds_admin" edge to the Guild entity by ids.
func (m *UserMutation) AddGuildsAdminIDs(ids ...uint64) {
	if m.guilds_admin == nil {
		m.guilds_admin = make(map[uint64]struct{})
	}
	for i := range ids {
		m.guilds_admin[ids[i]] = struct{}{}
	}
}

// ClearGuildsAdmin clears the "guilds_admin" edge to the Guild entity.
func (m *UserMutation) ClearGuildsAdmin() {
	m.clearedguilds_admin = true
}

// GuildsAdminCleared reports if the "guilds_admin" edge to the Guild entity was cleared.
func (m *UserMutation) GuildsAdminCleared() bool {
	return m.clearedguilds_admin
}

// RemoveGuildsAdminIDs removes the "guilds_admin" edge to the Guild entity by IDs.
func (m *UserMutation) RemoveGuildsAdminIDs(ids ...uint64) {
	if m.removedguilds_admin == nil {
		m.removedguilds_admin = make(map[uint64]struct{})
	}
	for i := range ids {
		delete(m.guilds_admin, ids[i])
		m.removedguilds_admin[ids[i]] = struct{}{}
	}
}

// RemovedGuildsAdmin returns the removed IDs of the "guilds_admin" edge to the Guild entity.
func (m *UserMutation) RemovedGuildsAdminIDs() (ids []uint64) {
	for id := range m.removedguilds_admin {
		ids = append(ids, id)
	}
	return
}

// GuildsAdminIDs returns the "guilds_admin" edge IDs in the mutation.
func (m *UserMutation) GuildsAdminIDs() (ids []uint64) {
	for id := range m.guilds_admin {
		ids = append(ids, id)
	}
	return
}

// ResetGuildsAdmin resets all changes to the "guilds_admin" edge.
func (m *UserMutation) ResetGuildsAdmin() {
	m.guilds_admin = nil
	m.clearedguilds_admin = false
	m.removedguilds_admin = nil
}

// AddMembershipIDs adds the "memberships" edge to the UserMembership entity by ids.
func (m *UserMutation) AddMembershipIDs(ids ...int) {
	if m.memberships == nil {
		m.memberships = make(map[int]struct{})
	}
	for i := range ids {
		m.memberships[ids[i]] = struct{}{}
	}
}

// ClearMemberships clears the "memberships" edge to the UserMembership entity.
func (m *UserMutation) ClearMemberships() {
	m.clearedmemberships = true
}

// MembershipsCleared reports if the "memberships" edge to the UserMembership entity was cleared.
func (m *UserMutation) MembershipsCleared() bool {
	return m.clearedmemberships
}

// RemoveMembershipIDs removes the "memberships" edge to the UserMembership entity by IDs.
func (m *UserMutation) RemoveMembershipIDs(ids ...int) {
	if m.removedmemberships == nil {
		m.removedmemberships = make(map[int]struct{})
	}
	for i := range ids {
		delete(m.memberships, ids[i])
		m.removedmemberships[ids[i]] = struct{}{}
	}
}

// RemovedMemberships returns the removed IDs of the "memberships" edge to the UserMembership entity.
func (m *UserMutation) RemovedMembershipsIDs() (ids []int) {
	for id := range m.removedmemberships {
		ids = append(ids, id)
	}
	return
}

// MembershipsIDs returns the "memberships" edge IDs in the mutation.
func (m *UserMutation) MembershipsIDs() (ids []int) {
	for id := range m.memberships {
		ids = append(ids, id)
	}
	return
}

// ResetMemberships resets all changes to the "memberships" edge.
func (m *UserMutation) ResetMemberships() {
	m.memberships = nil
	m.clearedmemberships = false
	m.removedmemberships = nil
}

// Where appends a list predicates to the UserMutation builder.
func (m *UserMutation) Where(ps ...predicate.User) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the UserMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *UserMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.User, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *UserMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *UserMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (User).
func (m *UserMutation) Type() string {
	return m.typ
}

// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *UserMutation) Fields() []string {
	fields := make([]string, 0, 6)
	if m.full_name != nil {
		fields = append(fields, user.FieldFullName)
	}
	if m.avatar_hash != nil {
		fields = append(fields, user.FieldAvatarHash)
	}
	if m.last_check != nil {
		fields = append(fields, user.FieldLastCheck)
	}
	if m.youtube_id != nil {
		fields = append(fields, user.FieldYoutubeID)
	}
	if m.youtube_token != nil {
		fields = append(fields, user.FieldYoutubeToken)
	}
	if m.discord_token != nil {
		fields = append(fields, user.FieldDiscordToken)
	}
	return fields
}

// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *UserMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case user.FieldFullName:
		return m.FullName()
	case user.FieldAvatarHash:
		return m.AvatarHash()
	case user.FieldLastCheck:
		return m.LastCheck()
	case user.FieldYoutubeID:
		return m.YoutubeID()
	case user.FieldYoutubeToken:
		return m.YoutubeToken()
	case user.FieldDiscordToken:
		return m.DiscordToken()
	}
	return nil, false
}

// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case user.FieldFullName:
		return m.OldFullName(ctx)
	case user.FieldAvatarHash:
		return m.OldAvatarHash(ctx)
	case user.FieldLastCheck:
		return m.OldLastCheck(ctx)
	case user.FieldYoutubeID:
		return m.OldYoutubeID(ctx)
	case user.FieldYoutubeToken:
		return m.OldYoutubeToken(ctx)
	case user.FieldDiscordToken:
		return m.OldDiscordToken(ctx)
	}
	return nil, fmt.Errorf("unknown User field %s", name)
}

// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *UserMutation) SetField(name string, value ent.Value) error {
	switch name {
	case user.FieldFullName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFullName(v)
		return nil
	case user.FieldAvatarHash:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetAvatarHash(v)
		return nil
	case user.FieldLastCheck:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLastCheck(v)
		return nil
	case user.FieldYoutubeID:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetYoutubeID(v)
		return nil
	case user.FieldYoutubeToken:
		v, ok := value.(*oauth2.Token)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetYoutubeToken(v)
		return nil
	case user.FieldDiscordToken:
		v, ok := value.(*oauth2.Token)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDiscordToken(v)
		return nil
	}
	return fmt.Errorf("unknown User field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *UserMutation) AddedFields() []string {
	return nil
}

// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *UserMutation) AddedField(name string) (ent.Value, bool) {
	return nil, false
}

// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *UserMutation) AddField(name string, value ent.Value) error {
	switch name {
	}
	return fmt.Errorf("unknown User numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *UserMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(user.FieldYoutubeID) {
		fields = append(fields, user.FieldYoutubeID)
	}
	if m.FieldCleared(user.FieldYoutubeToken) {
		fields = append(fields, user.FieldYoutubeToken)
	}
	if m.FieldCleared(user.FieldDiscordToken) {
		fields = append(fields, user.FieldDiscordToken)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *UserMutation) FieldCleared(name string) bool {
	_, ok := m.clearedFields[name]
	return ok
}

// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *UserMutation) ClearField(name string) error {
	switch name {
	case user.FieldYoutubeID:
		m.ClearYoutubeID()
		return nil
	case user.FieldYoutubeToken:
		m.ClearYoutubeToken()
		return nil
	case user.FieldDiscordToken:
		m.ClearDiscordToken()
		return nil
	}
	return fmt.Errorf("unknown User nullable field %s", name)
}

// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *UserMutation) ResetField(name string) error {
	switch name {
	case user.FieldFullName:
		m.ResetFullName()
		return nil
	case user.FieldAvatarHash:
		m.ResetAvatarHash()
		return nil
	case user.FieldLastCheck:
		m.ResetLastCheck()
		return nil
	case user.FieldYoutubeID:
		m.ResetYoutubeID()
		return nil
	case user.FieldYoutubeToken:
		m.ResetYoutubeToken()
		return nil
	case user.FieldDiscordToken:
		m.ResetDiscordToken()
		return nil
	}
	return fmt.Errorf("unknown User field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UserMutation) AddedEdges() []string {
	edges := make([]string, 0, 3)
	if m.guilds != nil {
		edges = append(edges, user.EdgeGuilds)
	}
	if m.guilds_admin != nil {
		edges = append(edges, user.EdgeGuildsAdmin)
	}
	if m.memberships != nil {
		edges = append(edges, user.EdgeMemberships)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *UserMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case user.EdgeGuilds:
		ids := make([]ent.Value, 0, len(m.guilds))
		for id := range m.guilds {
			ids = append(ids, id)
		}
		return ids
	case user.EdgeGuildsAdmin:
		ids := make([]ent.Value, 0, len(m.guilds_admin))
		for id := range m.guilds_admin {
			ids = append(ids, id)
		}
		return ids
	case user.EdgeMemberships:
		ids := make([]ent.Value, 0, len(m.memberships))
		for id := range m.memberships {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UserMutation) RemovedEdges() []string {
	edges := make([]string, 0, 3)
	if m.removedguilds != nil {
		edges = append(edges, user.EdgeGuilds)
	}
	if m.removedguilds_admin != nil {
		edges = append(edges, user.EdgeGuildsAdmin)
	}
	if m.removedmemberships != nil {
		edges = append(edges, user.EdgeMemberships)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *UserMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case user.EdgeGuilds:
		ids := make([]ent.Value, 0, len(m.removedguilds))
		for id := range m.removedguilds {
			ids = append(ids, id)
		}
		return ids
	case user.EdgeGuildsAdmin:
		ids := make([]ent.Value, 0, len(m.removedguilds_admin))
		for id := range m.removedguilds_admin {
			ids = append(ids, id)
		}
		return ids
	case user.EdgeMemberships:
		ids := make([]ent.Value, 0, len(m.removedmemberships))
		for id := range m.removedmemberships {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UserMutation) ClearedEdges() []string {
	edges := make([]string, 0, 3)
	if m.clearedguilds {
		edges = append(edges, user.EdgeGuilds)
	}
	if m.clearedguilds_admin {
		edges = append(edges, user.EdgeGuildsAdmin)
	}
	if m.clearedmemberships {
		edges = append(edges, user.EdgeMemberships)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *UserMutation) EdgeCleared(name string) bool {
	switch name {
	case user.EdgeGuilds:
		return m.clearedguilds
	case user.EdgeGuildsAdmin:
		return m.clearedguilds_admin
	case user.EdgeMemberships:
		return m.clearedmemberships
	}
	return false
}

// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *UserMutation) ClearEdge(name string) error {
	switch name {
	}
	return fmt.Errorf("unknown User unique edge %s", name)
}

// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *UserMutation) ResetEdge(name string) error {
	switch name {
	case user.EdgeGuilds:
		m.ResetGuilds()
		return nil
	case user.EdgeGuildsAdmin:
		m.ResetGuildsAdmin()
		return nil
	case user.EdgeMemberships:
		m.ResetMemberships()
		return nil
	}
	return fmt.Errorf("unknown User edge %s", name)
}

// UserMembershipMutation represents an operation that mutates the UserMembership nodes in the graph.
type UserMembershipMutation struct {
	config
	op                    Op
	typ                   string
	id                    *int
	first_failed          *time.Time
	last_verified         *time.Time
	fail_count            *int
	addfail_count         *int
	clearedFields         map[string]struct{}
	user                  *uint64
	cleareduser           bool
	youtube_talent        *string
	clearedyoutube_talent bool
	roles                 map[uint64]struct{}
	removedroles          map[uint64]struct{}
	clearedroles          bool
	done                  bool
	oldValue              func(context.Context) (*UserMembership, error)
	predicates            []predicate.UserMembership
}

var _ ent.Mutation = (*UserMembershipMutation)(nil)

// usermembershipOption allows management of the mutation configuration using functional options.
type usermembershipOption func(*UserMembershipMutation)

// newUserMembershipMutation creates new mutation for the UserMembership entity.
func newUserMembershipMutation(c config, op Op, opts ...usermembershipOption) *UserMembershipMutation {
	m := &UserMembershipMutation{
		config:        c,
		op:            op,
		typ:           TypeUserMembership,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withUserMembershipID sets the ID field of the mutation.
func withUserMembershipID(id int) usermembershipOption {
	return func(m *UserMembershipMutation) {
		var (
			err   error
			once  sync.Once
			value *UserMembership
		)
		m.oldValue = func(ctx context.Context) (*UserMembership, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().UserMembership.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withUserMembership sets the old UserMembership of the mutation.
func withUserMembership(node *UserMembership) usermembershipOption {
	return func(m *UserMembershipMutation) {
		m.oldValue = func(context.Context) (*UserMembership, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}

// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m UserMembershipMutation) Client() *Client {
	client := &Client{config: m.config}
	client.init()
	return client
}

// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m UserMembershipMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *UserMembershipMutation) ID() (id int, exists bool) {
	if m.id == nil {
		return
	}
	return *m.id, true
}

// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *UserMembershipMutation) IDs(ctx context.Context) ([]int, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []int{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().UserMembership.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetFirstFailed sets the "first_failed" field.
func (m *UserMembershipMutation) SetFirstFailed(t time.Time) {
	m.first_failed = &t
}

// FirstFailed returns the value of the "first_failed" field in the mutation.
func (m *UserMembershipMutation) FirstFailed() (r time.Time, exists bool) {
	v := m.first_failed
	if v == nil {
		return
	}
	return *v, true
}

// OldFirstFailed returns the old "first_failed" field's value of the UserMembership entity.
// If the UserMembership object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMembershipMutation) OldFirstFailed(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldFirstFailed is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldFirstFailed requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldFirstFailed: %w", err)
	}
	return oldValue.FirstFailed, nil
}

// ClearFirstFailed clears the value of the "first_failed" field.
func (m *UserMembershipMutation) ClearFirstFailed() {
	m.first_failed = nil
	m.clearedFields[usermembership.FieldFirstFailed] = struct{}{}
}

// FirstFailedCleared returns if the "first_failed" field was cleared in this mutation.
func (m *UserMembershipMutation) FirstFailedCleared() bool {
	_, ok := m.clearedFields[usermembership.FieldFirstFailed]
	return ok
}

// ResetFirstFailed resets all changes to the "first_failed" field.
func (m *UserMembershipMutation) ResetFirstFailed() {
	m.first_failed = nil
	delete(m.clearedFields, usermembership.FieldFirstFailed)
}

// SetLastVerified sets the "last_verified" field.
func (m *UserMembershipMutation) SetLastVerified(t time.Time) {
	m.last_verified = &t
}

// LastVerified returns the value of the "last_verified" field in the mutation.
func (m *UserMembershipMutation) LastVerified() (r time.Time, exists bool) {
	v := m.last_verified
	if v == nil {
		return
	}
	return *v, true
}

// OldLastVerified returns the old "last_verified" field's value of the UserMembership entity.
// If the UserMembership object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMembershipMutation) OldLastVerified(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldLastVerified is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldLastVerified requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldLastVerified: %w", err)
	}
	return oldValue.LastVerified, nil
}

// ResetLastVerified resets all changes to the "last_verified" field.
func (m *UserMembershipMutation) ResetLastVerified() {
	m.last_verified = nil
}

// SetFailCount sets the "fail_count" field.
func (m *UserMembershipMutation) SetFailCount(i int) {
	m.fail_count = &i
	m.addfail_count = nil
}

// FailCount returns the value of the "fail_count" field in the mutation.
func (m *UserMembershipMutation) FailCount() (r int, exists bool) {
	v := m.fail_count
	if v == nil {
		return
	}
	return *v, true
}

// OldFailCount returns the old "fail_count" field's value of the UserMembership entity.
// If the UserMembership object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *UserMembershipMutation) OldFailCount(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldFailCount is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldFailCount requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldFailCount: %w", err)
	}
	return oldValue.FailCount, nil
}

// AddFailCount adds i to the "fail_count" field.
func (m *UserMembershipMutation) AddFailCount(i int) {
	if m.addfail_count != nil {
		*m.addfail_count += i
	} else {
		m.addfail_count = &i
	}
}

// AddedFailCount returns the value that was added to the "fail_count" field in this mutation.
func (m *UserMembershipMutation) AddedFailCount() (r int, exists bool) {
	v := m.addfail_count
	if v == nil {
		return
	}
	return *v, true
}

// ResetFailCount resets all changes to the "fail_count" field.
func (m *UserMembershipMutation) ResetFailCount() {
	m.fail_count = nil
	m.addfail_count = nil
}

// SetUserID sets the "user" edge to the User entity by id.
func (m *UserMembershipMutation) SetUserID(id uint64) {
	m.user = &id
}

// ClearUser clears the "user" edge to the User entity.
func (m *UserMembershipMutation) ClearUser() {
	m.cleareduser = true
}

// UserCleared reports if the "user" edge to the User entity was cleared.
func (m *UserMembershipMutation) UserCleared() bool {
	return m.cleareduser
}

// UserID returns the "user" edge ID in the mutation.
func (m *UserMembershipMutation) UserID() (id uint64, exists bool) {
	if m.user != nil {
		return *m.user, true
	}
	return
}

// UserIDs returns the "user" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// UserID instead. It exists only for internal usage by the builders.
func (m *UserMembershipMutation) UserIDs() (ids []uint64) {
	if id := m.user; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetUser resets all changes to the "user" edge.
func (m *UserMembershipMutation) ResetUser() {
	m.user = nil
	m.cleareduser = false
}

// SetYoutubeTalentID sets the "youtube_talent" edge to the YouTubeTalent entity by id.
func (m *UserMembershipMutation) SetYoutubeTalentID(id string) {
	m.youtube_talent = &id
}

// ClearYoutubeTalent clears the "youtube_talent" edge to the YouTubeTalent entity.
func (m *UserMembershipMutation) ClearYoutubeTalent() {
	m.clearedyoutube_talent = true
}

// YoutubeTalentCleared reports if the "youtube_talent" edge to the YouTubeTalent entity was cleared.
func (m *UserMembershipMutation) YoutubeTalentCleared() bool {
	return m.clearedyoutube_talent
}

// YoutubeTalentID returns the "youtube_talent" edge ID in the mutation.
func (m *UserMembershipMutation) YoutubeTalentID() (id string, exists bool) {
	if m.youtube_talent != nil {
		return *m.youtube_talent, true
	}
	return
}

// YoutubeTalentIDs returns the "youtube_talent" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// YoutubeTalentID instead. It exists only for internal usage by the builders.
func (m *UserMembershipMutation) YoutubeTalentIDs() (ids []string) {
	if id := m.youtube_talent; id != nil {
		ids = append(ids, *id)
	}
	return
}

// ResetYoutubeTalent resets all changes to the "youtube_talent" edge.
func (m *UserMembershipMutation) ResetYoutubeTalent() {
	m.youtube_talent = nil
	m.clearedyoutube_talent = false
}

// AddRoleIDs adds the "roles" edge to the GuildRole entity by ids.
func (m *UserMembershipMutation) AddRoleIDs(ids ...uint64) {
	if m.roles == nil {
		m.roles = make(map[uint64]struct{})
	}
	for i := range ids {
		m.roles[ids[i]] = struct{}{}
	}
}

// ClearRoles clears the "roles" edge to the GuildRole entity.
func (m *UserMembershipMutation) ClearRoles() {
	m.clearedroles = true
}

// RolesCleared reports if the "roles" edge to the GuildRole entity was cleared.
func (m *UserMembershipMutation) RolesCleared() bool {
	return m.clearedroles
}

// RemoveRoleIDs removes the "roles" edge to the GuildRole entity by IDs.
func (m *UserMembershipMutation) RemoveRoleIDs(ids ...uint64) {
	if m.removedroles == nil {
		m.removedroles = make(map[uint64]struct{})
	}
	for i := range ids {
		delete(m.roles, ids[i])
		m.removedroles[ids[i]] = struct{}{}
	}
}

// RemovedRoles returns the removed IDs of the "roles" edge to the GuildRole entity.
func (m *UserMembershipMutation) RemovedRolesIDs() (ids []uint64) {
	for id := range m.removedroles {
		ids = append(ids, id)
	}
	return
}

// RolesIDs returns the "roles" edge IDs in the mutation.
func (m *UserMembershipMutation) RolesIDs() (ids []uint64) {
	for id := range m.roles {
		ids = append(ids, id)
	}
	return
}

// ResetRoles resets all changes to the "roles" edge.
func (m *UserMembershipMutation) ResetRoles() {
	m.roles = nil
	m.clearedroles = false
	m.removedroles = nil
}

// Where appends a list predicates to the UserMembershipMutation builder.
func (m *UserMembershipMutation) Where(ps ...predicate.UserMembership) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the UserMembershipMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *UserMembershipMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.UserMembership, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *UserMembershipMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *UserMembershipMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (UserMembership).
func (m *UserMembershipMutation) Type() string {
	return m.typ
}

// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *UserMembershipMutation) Fields() []string {
	fields := make([]string, 0, 3)
	if m.first_failed != nil {
		fields = append(fields, usermembership.FieldFirstFailed)
	}
	if m.last_verified != nil {
		fields = append(fields, usermembership.FieldLastVerified)
	}
	if m.fail_count != nil {
		fields = append(fields, usermembership.FieldFailCount)
	}
	return fields
}

// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *UserMembershipMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case usermembership.FieldFirstFailed:
		return m.FirstFailed()
	case usermembership.FieldLastVerified:
		return m.LastVerified()
	case usermembership.FieldFailCount:
		return m.FailCount()
	}
	return nil, false
}

// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *UserMembershipMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case usermembership.FieldFirstFailed:
		return m.OldFirstFailed(ctx)
	case usermembership.FieldLastVerified:
		return m.OldLastVerified(ctx)
	case usermembership.FieldFailCount:
		return m.OldFailCount(ctx)
	}
	return nil, fmt.Errorf("unknown UserMembership field %s", name)
}

// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *UserMembershipMutation) SetField(name string, value ent.Value) error {
	switch name {
	case usermembership.FieldFirstFailed:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFirstFailed(v)
		return nil
	case usermembership.FieldLastVerified:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLastVerified(v)
		return nil
	case usermembership.FieldFailCount:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetFailCount(v)
		return nil
	}
	return fmt.Errorf("unknown UserMembership field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *UserMembershipMutation) AddedFields() []string {
	var fields []string
	if m.addfail_count != nil {
		fields = append(fields, usermembership.FieldFailCount)
	}
	return fields
}

// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *UserMembershipMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case usermembership.FieldFailCount:
		return m.AddedFailCount()
	}
	return nil, false
}

// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *UserMembershipMutation) AddField(name string, value ent.Value) error {
	switch name {
	case usermembership.FieldFailCount:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddFailCount(v)
		return nil
	}
	return fmt.Errorf("unknown UserMembership numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *UserMembershipMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(usermembership.FieldFirstFailed) {
		fields = append(fields, usermembership.FieldFirstFailed)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *UserMembershipMutation) FieldCleared(name string) bool {
	_, ok := m.clearedFields[name]
	return ok
}

// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *UserMembershipMutation) ClearField(name string) error {
	switch name {
	case usermembership.FieldFirstFailed:
		m.ClearFirstFailed()
		return nil
	}
	return fmt.Errorf("unknown UserMembership nullable field %s", name)
}

// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *UserMembershipMutation) ResetField(name string) error {
	switch name {
	case usermembership.FieldFirstFailed:
		m.ResetFirstFailed()
		return nil
	case usermembership.FieldLastVerified:
		m.ResetLastVerified()
		return nil
	case usermembership.FieldFailCount:
		m.ResetFailCount()
		return nil
	}
	return fmt.Errorf("unknown UserMembership field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UserMembershipMutation) AddedEdges() []string {
	edges := make([]string, 0, 3)
	if m.user != nil {
		edges = append(edges, usermembership.EdgeUser)
	}
	if m.youtube_talent != nil {
		edges = append(edges, usermembership.EdgeYoutubeTalent)
	}
	if m.roles != nil {
		edges = append(edges, usermembership.EdgeRoles)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *UserMembershipMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case usermembership.EdgeUser:
		if id := m.user; id != nil {
			return []ent.Value{*id}
		}
	case usermembership.EdgeYoutubeTalent:
		if id := m.youtube_talent; id != nil {
			return []ent.Value{*id}
		}
	case usermembership.EdgeRoles:
		ids := make([]ent.Value, 0, len(m.roles))
		for id := range m.roles {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UserMembershipMutation) RemovedEdges() []string {
	edges := make([]string, 0, 3)
	if m.removedroles != nil {
		edges = append(edges, usermembership.EdgeRoles)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *UserMembershipMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case usermembership.EdgeRoles:
		ids := make([]ent.Value, 0, len(m.removedroles))
		for id := range m.removedroles {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UserMembershipMutation) ClearedEdges() []string {
	edges := make([]string, 0, 3)
	if m.cleareduser {
		edges = append(edges, usermembership.EdgeUser)
	}
	if m.clearedyoutube_talent {
		edges = append(edges, usermembership.EdgeYoutubeTalent)
	}
	if m.clearedroles {
		edges = append(edges, usermembership.EdgeRoles)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *UserMembershipMutation) EdgeCleared(name string) bool {
	switch name {
	case usermembership.EdgeUser:
		return m.cleareduser
	case usermembership.EdgeYoutubeTalent:
		return m.clearedyoutube_talent
	case usermembership.EdgeRoles:
		return m.clearedroles
	}
	return false
}

// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *UserMembershipMutation) ClearEdge(name string) error {
	switch name {
	case usermembership.EdgeUser:
		m.ClearUser()
		return nil
	case usermembership.EdgeYoutubeTalent:
		m.ClearYoutubeTalent()
		return nil
	}
	return fmt.Errorf("unknown UserMembership unique edge %s", name)
}

// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *UserMembershipMutation) ResetEdge(name string) error {
	switch name {
	case usermembership.EdgeUser:
		m.ResetUser()
		return nil
	case usermembership.EdgeYoutubeTalent:
		m.ResetYoutubeTalent()
		return nil
	case usermembership.EdgeRoles:
		m.ResetRoles()
		return nil
	}
	return fmt.Errorf("unknown UserMembership edge %s", name)
}

// YouTubeTalentMutation represents an operation that mutates the YouTubeTalent nodes in the graph.
type YouTubeTalentMutation struct {
	config
	op                            Op
	typ                           string
	id                            *string
	channel_name                  *string
	thumbnail_url                 *string
	membership_video_id           *string
	last_membership_video_id_miss *time.Time
	last_updated                  *time.Time
	disabled                      *time.Time
	disabled_permanently          *bool
	clearedFields                 map[string]struct{}
	guilds                        map[uint64]struct{}
	removedguilds                 map[uint64]struct{}
	clearedguilds                 bool
	roles                         map[uint64]struct{}
	removedroles                  map[uint64]struct{}
	clearedroles                  bool
	memberships                   map[int]struct{}
	removedmemberships            map[int]struct{}
	clearedmemberships            bool
	done                          bool
	oldValue                      func(context.Context) (*YouTubeTalent, error)
	predicates                    []predicate.YouTubeTalent
}

var _ ent.Mutation = (*YouTubeTalentMutation)(nil)

// youtubetalentOption allows management of the mutation configuration using functional options.
type youtubetalentOption func(*YouTubeTalentMutation)

// newYouTubeTalentMutation creates new mutation for the YouTubeTalent entity.
func newYouTubeTalentMutation(c config, op Op, opts ...youtubetalentOption) *YouTubeTalentMutation {
	m := &YouTubeTalentMutation{
		config:        c,
		op:            op,
		typ:           TypeYouTubeTalent,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}

// withYouTubeTalentID sets the ID field of the mutation.
func withYouTubeTalentID(id string) youtubetalentOption {
	return func(m *YouTubeTalentMutation) {
		var (
			err   error
			once  sync.Once
			value *YouTubeTalent
		)
		m.oldValue = func(ctx context.Context) (*YouTubeTalent, error) {
			once.Do(func() {
				if m.done {
					err = errors.New("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().YouTubeTalent.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}

// withYouTubeTalent sets the old YouTubeTalent of the mutation.
func withYouTubeTalent(node *YouTubeTalent) youtubetalentOption {
	return func(m *YouTubeTalentMutation) {
		m.oldValue = func(context.Context) (*YouTubeTalent, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}

// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m YouTubeTalentMutation) Client() *Client {
	client := &Client{config: m.config}
	client.init()
	return client
}

// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m YouTubeTalentMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, errors.New("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}

// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of YouTubeTalent entities.
func (m *YouTubeTalentMutation) SetID(id string) {
	m.id = &id
}

// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *YouTubeTalentMutation) ID() (id string, exists bool) {
	if m.id == nil {
		return
	}
	return *m.id, true
}

// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *YouTubeTalentMutation) IDs(ctx context.Context) ([]string, error) {
	switch {
	case m.op.Is(OpUpdateOne | OpDeleteOne):
		id, exists := m.ID()
		if exists {
			return []string{id}, nil
		}
		fallthrough
	case m.op.Is(OpUpdate | OpDelete):
		return m.Client().YouTubeTalent.Query().Where(m.predicates...).IDs(ctx)
	default:
		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
	}
}

// SetChannelName sets the "channel_name" field.
func (m *YouTubeTalentMutation) SetChannelName(s string) {
	m.channel_name = &s
}

// ChannelName returns the value of the "channel_name" field in the mutation.
func (m *YouTubeTalentMutation) ChannelName() (r string, exists bool) {
	v := m.channel_name
	if v == nil {
		return
	}
	return *v, true
}

// OldChannelName returns the old "channel_name" field's value of the YouTubeTalent entity.
// If the YouTubeTalent object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *YouTubeTalentMutation) OldChannelName(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldChannelName is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldChannelName requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldChannelName: %w", err)
	}
	return oldValue.ChannelName, nil
}

// ResetChannelName resets all changes to the "channel_name" field.
func (m *YouTubeTalentMutation) ResetChannelName() {
	m.channel_name = nil
}

// SetThumbnailURL sets the "thumbnail_url" field.
func (m *YouTubeTalentMutation) SetThumbnailURL(s string) {
	m.thumbnail_url = &s
}

// ThumbnailURL returns the value of the "thumbnail_url" field in the mutation.
func (m *YouTubeTalentMutation) ThumbnailURL() (r string, exists bool) {
	v := m.thumbnail_url
	if v == nil {
		return
	}
	return *v, true
}

// OldThumbnailURL returns the old "thumbnail_url" field's value of the YouTubeTalent entity.
// If the YouTubeTalent object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *YouTubeTalentMutation) OldThumbnailURL(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldThumbnailURL is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldThumbnailURL requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldThumbnailURL: %w", err)
	}
	return oldValue.ThumbnailURL, nil
}

// ResetThumbnailURL resets all changes to the "thumbnail_url" field.
func (m *YouTubeTalentMutation) ResetThumbnailURL() {
	m.thumbnail_url = nil
}

// SetMembershipVideoID sets the "membership_video_id" field.
func (m *YouTubeTalentMutation) SetMembershipVideoID(s string) {
	m.membership_video_id = &s
}

// MembershipVideoID returns the value of the "membership_video_id" field in the mutation.
func (m *YouTubeTalentMutation) MembershipVideoID() (r string, exists bool) {
	v := m.membership_video_id
	if v == nil {
		return
	}
	return *v, true
}

// OldMembershipVideoID returns the old "membership_video_id" field's value of the YouTubeTalent entity.
// If the YouTubeTalent object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *YouTubeTalentMutation) OldMembershipVideoID(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldMembershipVideoID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldMembershipVideoID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldMembershipVideoID: %w", err)
	}
	return oldValue.MembershipVideoID, nil
}

// ClearMembershipVideoID clears the value of the "membership_video_id" field.
func (m *YouTubeTalentMutation) ClearMembershipVideoID() {
	m.membership_video_id = nil
	m.clearedFields[youtubetalent.FieldMembershipVideoID] = struct{}{}
}

// MembershipVideoIDCleared returns if the "membership_video_id" field was cleared in this mutation.
func (m *YouTubeTalentMutation) MembershipVideoIDCleared() bool {
	_, ok := m.clearedFields[youtubetalent.FieldMembershipVideoID]
	return ok
}

// ResetMembershipVideoID resets all changes to the "membership_video_id" field.
func (m *YouTubeTalentMutation) ResetMembershipVideoID() {
	m.membership_video_id = nil
	delete(m.clearedFields, youtubetalent.FieldMembershipVideoID)
}

// SetLastMembershipVideoIDMiss sets the "last_membership_video_id_miss" field.
func (m *YouTubeTalentMutation) SetLastMembershipVideoIDMiss(t time.Time) {
	m.last_membership_video_id_miss = &t
}

// LastMembershipVideoIDMiss returns the value of the "last_membership_video_id_miss" field in the mutation.
func (m *YouTubeTalentMutation) LastMembershipVideoIDMiss() (r time.Time, exists bool) {
	v := m.last_membership_video_id_miss
	if v == nil {
		return
	}
	return *v, true
}

// OldLastMembershipVideoIDMiss returns the old "last_membership_video_id_miss" field's value of the YouTubeTalent entity.
// If the YouTubeTalent object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *YouTubeTalentMutation) OldLastMembershipVideoIDMiss(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldLastMembershipVideoIDMiss is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldLastMembershipVideoIDMiss requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldLastMembershipVideoIDMiss: %w", err)
	}
	return oldValue.LastMembershipVideoIDMiss, nil
}

// ClearLastMembershipVideoIDMiss clears the value of the "last_membership_video_id_miss" field.
func (m *YouTubeTalentMutation) ClearLastMembershipVideoIDMiss() {
	m.last_membership_video_id_miss = nil
	m.clearedFields[youtubetalent.FieldLastMembershipVideoIDMiss] = struct{}{}
}

// LastMembershipVideoIDMissCleared returns if the "last_membership_video_id_miss" field was cleared in this mutation.
func (m *YouTubeTalentMutation) LastMembershipVideoIDMissCleared() bool {
	_, ok := m.clearedFields[youtubetalent.FieldLastMembershipVideoIDMiss]
	return ok
}

// ResetLastMembershipVideoIDMiss resets all changes to the "last_membership_video_id_miss" field.
func (m *YouTubeTalentMutation) ResetLastMembershipVideoIDMiss() {
	m.last_membership_video_id_miss = nil
	delete(m.clearedFields, youtubetalent.FieldLastMembershipVideoIDMiss)
}

// SetLastUpdated sets the "last_updated" field.
func (m *YouTubeTalentMutation) SetLastUpdated(t time.Time) {
	m.last_updated = &t
}

// LastUpdated returns the value of the "last_updated" field in the mutation.
func (m *YouTubeTalentMutation) LastUpdated() (r time.Time, exists bool) {
	v := m.last_updated
	if v == nil {
		return
	}
	return *v, true
}

// OldLastUpdated returns the old "last_updated" field's value of the YouTubeTalent entity.
// If the YouTubeTalent object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *YouTubeTalentMutation) OldLastUpdated(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldLastUpdated is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldLastUpdated requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldLastUpdated: %w", err)
	}
	return oldValue.LastUpdated, nil
}

// ResetLastUpdated resets all changes to the "last_updated" field.
func (m *YouTubeTalentMutation) ResetLastUpdated() {
	m.last_updated = nil
}

// SetDisabled sets the "disabled" field.
func (m *YouTubeTalentMutation) SetDisabled(t time.Time) {
	m.disabled = &t
}

// Disabled returns the value of the "disabled" field in the mutation.
func (m *YouTubeTalentMutation) Disabled() (r time.Time, exists bool) {
	v := m.disabled
	if v == nil {
		return
	}
	return *v, true
}

// OldDisabled returns the old "disabled" field's value of the YouTubeTalent entity.
// If the YouTubeTalent object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *YouTubeTalentMutation) OldDisabled(ctx context.Context) (v time.Time, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldDisabled is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldDisabled requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldDisabled: %w", err)
	}
	return oldValue.Disabled, nil
}

// ClearDisabled clears the value of the "disabled" field.
func (m *YouTubeTalentMutation) ClearDisabled() {
	m.disabled = nil
	m.clearedFields[youtubetalent.FieldDisabled] = struct{}{}
}

// DisabledCleared returns if the "disabled" field was cleared in this mutation.
func (m *YouTubeTalentMutation) DisabledCleared() bool {
	_, ok := m.clearedFields[youtubetalent.FieldDisabled]
	return ok
}

// ResetDisabled resets all changes to the "disabled" field.
func (m *YouTubeTalentMutation) ResetDisabled() {
	m.disabled = nil
	delete(m.clearedFields, youtubetalent.FieldDisabled)
}

// SetDisabledPermanently sets the "disabled_permanently" field.
func (m *YouTubeTalentMutation) SetDisabledPermanently(b bool) {
	m.disabled_permanently = &b
}

// DisabledPermanently returns the value of the "disabled_permanently" field in the mutation.
func (m *YouTubeTalentMutation) DisabledPermanently() (r bool, exists bool) {
	v := m.disabled_permanently
	if v == nil {
		return
	}
	return *v, true
}

// OldDisabledPermanently returns the old "disabled_permanently" field's value of the YouTubeTalent entity.
// If the YouTubeTalent object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *YouTubeTalentMutation) OldDisabledPermanently(ctx context.Context) (v bool, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, errors.New("OldDisabledPermanently is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, errors.New("OldDisabledPermanently requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldDisabledPermanently: %w", err)
	}
	return oldValue.DisabledPermanently, nil
}

// ResetDisabledPermanently resets all changes to the "disabled_permanently" field.
func (m *YouTubeTalentMutation) ResetDisabledPermanently() {
	m.disabled_permanently = nil
}

// AddGuildIDs adds the "guilds" edge to the Guild entity by ids.
func (m *YouTubeTalentMutation) AddGuildIDs(ids ...uint64) {
	if m.guilds == nil {
		m.guilds = make(map[uint64]struct{})
	}
	for i := range ids {
		m.guilds[ids[i]] = struct{}{}
	}
}

// ClearGuilds clears the "guilds" edge to the Guild entity.
func (m *YouTubeTalentMutation) ClearGuilds() {
	m.clearedguilds = true
}

// GuildsCleared reports if the "guilds" edge to the Guild entity was cleared.
func (m *YouTubeTalentMutation) GuildsCleared() bool {
	return m.clearedguilds
}

// RemoveGuildIDs removes the "guilds" edge to the Guild entity by IDs.
func (m *YouTubeTalentMutation) RemoveGuildIDs(ids ...uint64) {
	if m.removedguilds == nil {
		m.removedguilds = make(map[uint64]struct{})
	}
	for i := range ids {
		delete(m.guilds, ids[i])
		m.removedguilds[ids[i]] = struct{}{}
	}
}

// RemovedGuilds returns the removed IDs of the "guilds" edge to the Guild entity.
func (m *YouTubeTalentMutation) RemovedGuildsIDs() (ids []uint64) {
	for id := range m.removedguilds {
		ids = append(ids, id)
	}
	return
}

// GuildsIDs returns the "guilds" edge IDs in the mutation.
func (m *YouTubeTalentMutation) GuildsIDs() (ids []uint64) {
	for id := range m.guilds {
		ids = append(ids, id)
	}
	return
}

// ResetGuilds resets all changes to the "guilds" edge.
func (m *YouTubeTalentMutation) ResetGuilds() {
	m.guilds = nil
	m.clearedguilds = false
	m.removedguilds = nil
}

// AddRoleIDs adds the "roles" edge to the GuildRole entity by ids.
func (m *YouTubeTalentMutation) AddRoleIDs(ids ...uint64) {
	if m.roles == nil {
		m.roles = make(map[uint64]struct{})
	}
	for i := range ids {
		m.roles[ids[i]] = struct{}{}
	}
}

// ClearRoles clears the "roles" edge to the GuildRole entity.
func (m *YouTubeTalentMutation) ClearRoles() {
	m.clearedroles = true
}

// RolesCleared reports if the "roles" edge to the GuildRole entity was cleared.
func (m *YouTubeTalentMutation) RolesCleared() bool {
	return m.clearedroles
}

// RemoveRoleIDs removes the "roles" edge to the GuildRole entity by IDs.
func (m *YouTubeTalentMutation) RemoveRoleIDs(ids ...uint64) {
	if m.removedroles == nil {
		m.removedroles = make(map[uint64]struct{})
	}
	for i := range ids {
		delete(m.roles, ids[i])
		m.removedroles[ids[i]] = struct{}{}
	}
}

// RemovedRoles returns the removed IDs of the "roles" edge to the GuildRole entity.
func (m *YouTubeTalentMutation) RemovedRolesIDs() (ids []uint64) {
	for id := range m.removedroles {
		ids = append(ids, id)
	}
	return
}

// RolesIDs returns the "roles" edge IDs in the mutation.
func (m *YouTubeTalentMutation) RolesIDs() (ids []uint64) {
	for id := range m.roles {
		ids = append(ids, id)
	}
	return
}

// ResetRoles resets all changes to the "roles" edge.
func (m *YouTubeTalentMutation) ResetRoles() {
	m.roles = nil
	m.clearedroles = false
	m.removedroles = nil
}

// AddMembershipIDs adds the "memberships" edge to the UserMembership entity by ids.
func (m *YouTubeTalentMutation) AddMembershipIDs(ids ...int) {
	if m.memberships == nil {
		m.memberships = make(map[int]struct{})
	}
	for i := range ids {
		m.memberships[ids[i]] = struct{}{}
	}
}

// ClearMemberships clears the "memberships" edge to the UserMembership entity.
func (m *YouTubeTalentMutation) ClearMemberships() {
	m.clearedmemberships = true
}

// MembershipsCleared reports if the "memberships" edge to the UserMembership entity was cleared.
func (m *YouTubeTalentMutation) MembershipsCleared() bool {
	return m.clearedmemberships
}

// RemoveMembershipIDs removes the "memberships" edge to the UserMembership entity by IDs.
func (m *YouTubeTalentMutation) RemoveMembershipIDs(ids ...int) {
	if m.removedmemberships == nil {
		m.removedmemberships = make(map[int]struct{})
	}
	for i := range ids {
		delete(m.memberships, ids[i])
		m.removedmemberships[ids[i]] = struct{}{}
	}
}

// RemovedMemberships returns the removed IDs of the "memberships" edge to the UserMembership entity.
func (m *YouTubeTalentMutation) RemovedMembershipsIDs() (ids []int) {
	for id := range m.removedmemberships {
		ids = append(ids, id)
	}
	return
}

// MembershipsIDs returns the "memberships" edge IDs in the mutation.
func (m *YouTubeTalentMutation) MembershipsIDs() (ids []int) {
	for id := range m.memberships {
		ids = append(ids, id)
	}
	return
}

// ResetMemberships resets all changes to the "memberships" edge.
func (m *YouTubeTalentMutation) ResetMemberships() {
	m.memberships = nil
	m.clearedmemberships = false
	m.removedmemberships = nil
}

// Where appends a list predicates to the YouTubeTalentMutation builder.
func (m *YouTubeTalentMutation) Where(ps ...predicate.YouTubeTalent) {
	m.predicates = append(m.predicates, ps...)
}

// WhereP appends storage-level predicates to the YouTubeTalentMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *YouTubeTalentMutation) WhereP(ps ...func(*sql.Selector)) {
	p := make([]predicate.YouTubeTalent, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	m.Where(p...)
}

// Op returns the operation name.
func (m *YouTubeTalentMutation) Op() Op {
	return m.op
}

// SetOp allows setting the mutation operation.
func (m *YouTubeTalentMutation) SetOp(op Op) {
	m.op = op
}

// Type returns the node type of this mutation (YouTubeTalent).
func (m *YouTubeTalentMutation) Type() string {
	return m.typ
}

// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *YouTubeTalentMutation) Fields() []string {
	fields := make([]string, 0, 7)
	if m.channel_name != nil {
		fields = append(fields, youtubetalent.FieldChannelName)
	}
	if m.thumbnail_url != nil {
		fields = append(fields, youtubetalent.FieldThumbnailURL)
	}
	if m.membership_video_id != nil {
		fields = append(fields, youtubetalent.FieldMembershipVideoID)
	}
	if m.last_membership_video_id_miss != nil {
		fields = append(fields, youtubetalent.FieldLastMembershipVideoIDMiss)
	}
	if m.last_updated != nil {
		fields = append(fields, youtubetalent.FieldLastUpdated)
	}
	if m.disabled != nil {
		fields = append(fields, youtubetalent.FieldDisabled)
	}
	if m.disabled_permanently != nil {
		fields = append(fields, youtubetalent.FieldDisabledPermanently)
	}
	return fields
}

// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *YouTubeTalentMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case youtubetalent.FieldChannelName:
		return m.ChannelName()
	case youtubetalent.FieldThumbnailURL:
		return m.ThumbnailURL()
	case youtubetalent.FieldMembershipVideoID:
		return m.MembershipVideoID()
	case youtubetalent.FieldLastMembershipVideoIDMiss:
		return m.LastMembershipVideoIDMiss()
	case youtubetalent.FieldLastUpdated:
		return m.LastUpdated()
	case youtubetalent.FieldDisabled:
		return m.Disabled()
	case youtubetalent.FieldDisabledPermanently:
		return m.DisabledPermanently()
	}
	return nil, false
}

// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *YouTubeTalentMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case youtubetalent.FieldChannelName:
		return m.OldChannelName(ctx)
	case youtubetalent.FieldThumbnailURL:
		return m.OldThumbnailURL(ctx)
	case youtubetalent.FieldMembershipVideoID:
		return m.OldMembershipVideoID(ctx)
	case youtubetalent.FieldLastMembershipVideoIDMiss:
		return m.OldLastMembershipVideoIDMiss(ctx)
	case youtubetalent.FieldLastUpdated:
		return m.OldLastUpdated(ctx)
	case youtubetalent.FieldDisabled:
		return m.OldDisabled(ctx)
	case youtubetalent.FieldDisabledPermanently:
		return m.OldDisabledPermanently(ctx)
	}
	return nil, fmt.Errorf("unknown YouTubeTalent field %s", name)
}

// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *YouTubeTalentMutation) SetField(name string, value ent.Value) error {
	switch name {
	case youtubetalent.FieldChannelName:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetChannelName(v)
		return nil
	case youtubetalent.FieldThumbnailURL:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetThumbnailURL(v)
		return nil
	case youtubetalent.FieldMembershipVideoID:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetMembershipVideoID(v)
		return nil
	case youtubetalent.FieldLastMembershipVideoIDMiss:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLastMembershipVideoIDMiss(v)
		return nil
	case youtubetalent.FieldLastUpdated:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetLastUpdated(v)
		return nil
	case youtubetalent.FieldDisabled:
		v, ok := value.(time.Time)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDisabled(v)
		return nil
	case youtubetalent.FieldDisabledPermanently:
		v, ok := value.(bool)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetDisabledPermanently(v)
		return nil
	}
	return fmt.Errorf("unknown YouTubeTalent field %s", name)
}

// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *YouTubeTalentMutation) AddedFields() []string {
	return nil
}

// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *YouTubeTalentMutation) AddedField(name string) (ent.Value, bool) {
	return nil, false
}

// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *YouTubeTalentMutation) AddField(name string, value ent.Value) error {
	switch name {
	}
	return fmt.Errorf("unknown YouTubeTalent numeric field %s", name)
}

// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *YouTubeTalentMutation) ClearedFields() []string {
	var fields []string
	if m.FieldCleared(youtubetalent.FieldMembershipVideoID) {
		fields = append(fields, youtubetalent.FieldMembershipVideoID)
	}
	if m.FieldCleared(youtubetalent.FieldLastMembershipVideoIDMiss) {
		fields = append(fields, youtubetalent.FieldLastMembershipVideoIDMiss)
	}
	if m.FieldCleared(youtubetalent.FieldDisabled) {
		fields = append(fields, youtubetalent.FieldDisabled)
	}
	return fields
}

// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *YouTubeTalentMutation) FieldCleared(name string) bool {
	_, ok := m.clearedFields[name]
	return ok
}

// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *YouTubeTalentMutation) ClearField(name string) error {
	switch name {
	case youtubetalent.FieldMembershipVideoID:
		m.ClearMembershipVideoID()
		return nil
	case youtubetalent.FieldLastMembershipVideoIDMiss:
		m.ClearLastMembershipVideoIDMiss()
		return nil
	case youtubetalent.FieldDisabled:
		m.ClearDisabled()
		return nil
	}
	return fmt.Errorf("unknown YouTubeTalent nullable field %s", name)
}

// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *YouTubeTalentMutation) ResetField(name string) error {
	switch name {
	case youtubetalent.FieldChannelName:
		m.ResetChannelName()
		return nil
	case youtubetalent.FieldThumbnailURL:
		m.ResetThumbnailURL()
		return nil
	case youtubetalent.FieldMembershipVideoID:
		m.ResetMembershipVideoID()
		return nil
	case youtubetalent.FieldLastMembershipVideoIDMiss:
		m.ResetLastMembershipVideoIDMiss()
		return nil
	case youtubetalent.FieldLastUpdated:
		m.ResetLastUpdated()
		return nil
	case youtubetalent.FieldDisabled:
		m.ResetDisabled()
		return nil
	case youtubetalent.FieldDisabledPermanently:
		m.ResetDisabledPermanently()
		return nil
	}
	return fmt.Errorf("unknown YouTubeTalent field %s", name)
}

// AddedEdges returns all edge names that were set/added in this mutation.
func (m *YouTubeTalentMutation) AddedEdges() []string {
	edges := make([]string, 0, 3)
	if m.guilds != nil {
		edges = append(edges, youtubetalent.EdgeGuilds)
	}
	if m.roles != nil {
		edges = append(edges, youtubetalent.EdgeRoles)
	}
	if m.memberships != nil {
		edges = append(edges, youtubetalent.EdgeMemberships)
	}
	return edges
}

// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *YouTubeTalentMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case youtubetalent.EdgeGuilds:
		ids := make([]ent.Value, 0, len(m.guilds))
		for id := range m.guilds {
			ids = append(ids, id)
		}
		return ids
	case youtubetalent.EdgeRoles:
		ids := make([]ent.Value, 0, len(m.roles))
		for id := range m.roles {
			ids = append(ids, id)
		}
		return ids
	case youtubetalent.EdgeMemberships:
		ids := make([]ent.Value, 0, len(m.memberships))
		for id := range m.memberships {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// RemovedEdges returns all edge names that were removed in this mutation.
func (m *YouTubeTalentMutation) RemovedEdges() []string {
	edges := make([]string, 0, 3)
	if m.removedguilds != nil {
		edges = append(edges, youtubetalent.EdgeGuilds)
	}
	if m.removedroles != nil {
		edges = append(edges, youtubetalent.EdgeRoles)
	}
	if m.removedmemberships != nil {
		edges = append(edges, youtubetalent.EdgeMemberships)
	}
	return edges
}

// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *YouTubeTalentMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case youtubetalent.EdgeGuilds:
		ids := make([]ent.Value, 0, len(m.removedguilds))
		for id := range m.removedguilds {
			ids = append(ids, id)
		}
		return ids
	case youtubetalent.EdgeRoles:
		ids := make([]ent.Value, 0, len(m.removedroles))
		for id := range m.removedroles {
			ids = append(ids, id)
		}
		return ids
	case youtubetalent.EdgeMemberships:
		ids := make([]ent.Value, 0, len(m.removedmemberships))
		for id := range m.removedmemberships {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}

// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *YouTubeTalentMutation) ClearedEdges() []string {
	edges := make([]string, 0, 3)
	if m.clearedguilds {
		edges = append(edges, youtubetalent.EdgeGuilds)
	}
	if m.clearedroles {
		edges = append(edges, youtubetalent.EdgeRoles)
	}
	if m.clearedmemberships {
		edges = append(edges, youtubetalent.EdgeMemberships)
	}
	return edges
}

// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *YouTubeTalentMutation) EdgeCleared(name string) bool {
	switch name {
	case youtubetalent.EdgeGuilds:
		return m.clearedguilds
	case youtubetalent.EdgeRoles:
		return m.clearedroles
	case youtubetalent.EdgeMemberships:
		return m.clearedmemberships
	}
	return false
}

// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *YouTubeTalentMutation) ClearEdge(name string) error {
	switch name {
	}
	return fmt.Errorf("unknown YouTubeTalent unique edge %s", name)
}

// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *YouTubeTalentMutation) ResetEdge(name string) error {
	switch name {
	case youtubetalent.EdgeGuilds:
		m.ResetGuilds()
		return nil
	case youtubetalent.EdgeRoles:
		m.ResetRoles()
		return nil
	case youtubetalent.EdgeMemberships:
		m.ResetMemberships()
		return nil
	}
	return fmt.Errorf("unknown YouTubeTalent edge %s", name)
}
