// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"log"
	"reflect"

	"github.com/member-gentei/member-gentei/gentei/ent/migrate"

	"entgo.io/ent"
	"entgo.io/ent/dialect"
	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"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/user"
	"github.com/member-gentei/member-gentei/gentei/ent/usermembership"
	"github.com/member-gentei/member-gentei/gentei/ent/youtubetalent"
)

// Client is the client that holds all ent builders.
type Client struct {
	config
	// Schema is the client for creating, migrating and dropping schema.
	Schema *migrate.Schema
	// Guild is the client for interacting with the Guild builders.
	Guild *GuildClient
	// GuildRole is the client for interacting with the GuildRole builders.
	GuildRole *GuildRoleClient
	// User is the client for interacting with the User builders.
	User *UserClient
	// UserMembership is the client for interacting with the UserMembership builders.
	UserMembership *UserMembershipClient
	// YouTubeTalent is the client for interacting with the YouTubeTalent builders.
	YouTubeTalent *YouTubeTalentClient
}

// NewClient creates a new client configured with the given options.
func NewClient(opts ...Option) *Client {
	client := &Client{config: newConfig(opts...)}
	client.init()
	return client
}

func (c *Client) init() {
	c.Schema = migrate.NewSchema(c.driver)
	c.Guild = NewGuildClient(c.config)
	c.GuildRole = NewGuildRoleClient(c.config)
	c.User = NewUserClient(c.config)
	c.UserMembership = NewUserMembershipClient(c.config)
	c.YouTubeTalent = NewYouTubeTalentClient(c.config)
}

type (
	// config is the configuration for the client and its builder.
	config struct {
		// driver used for executing database requests.
		driver dialect.Driver
		// debug enable a debug logging.
		debug bool
		// log used for logging on debug mode.
		log func(...any)
		// hooks to execute on mutations.
		hooks *hooks
		// interceptors to execute on queries.
		inters *inters
	}
	// Option function to configure the client.
	Option func(*config)
)

// newConfig creates a new config for the client.
func newConfig(opts ...Option) config {
	cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}}
	cfg.options(opts...)
	return cfg
}

// options applies the options on the config object.
func (c *config) options(opts ...Option) {
	for _, opt := range opts {
		opt(c)
	}
	if c.debug {
		c.driver = dialect.Debug(c.driver, c.log)
	}
}

// Debug enables debug logging on the ent.Driver.
func Debug() Option {
	return func(c *config) {
		c.debug = true
	}
}

// Log sets the logging function for debug mode.
func Log(fn func(...any)) Option {
	return func(c *config) {
		c.log = fn
	}
}

// Driver configures the client driver.
func Driver(driver dialect.Driver) Option {
	return func(c *config) {
		c.driver = driver
	}
}

// Open opens a database/sql.DB specified by the driver name and
// the data source name, and returns a new client attached to it.
// Optional parameters can be added for configuring the client.
func Open(driverName, dataSourceName string, options ...Option) (*Client, error) {
	switch driverName {
	case dialect.MySQL, dialect.Postgres, dialect.SQLite:
		drv, err := sql.Open(driverName, dataSourceName)
		if err != nil {
			return nil, err
		}
		return NewClient(append(options, Driver(drv))...), nil
	default:
		return nil, fmt.Errorf("unsupported driver: %q", driverName)
	}
}

// ErrTxStarted is returned when trying to start a new transaction from a transactional client.
var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction")

// Tx returns a new transactional client. The provided context
// is used until the transaction is committed or rolled back.
func (c *Client) Tx(ctx context.Context) (*Tx, error) {
	if _, ok := c.driver.(*txDriver); ok {
		return nil, ErrTxStarted
	}
	tx, err := newTx(ctx, c.driver)
	if err != nil {
		return nil, fmt.Errorf("ent: starting a transaction: %w", err)
	}
	cfg := c.config
	cfg.driver = tx
	return &Tx{
		ctx:            ctx,
		config:         cfg,
		Guild:          NewGuildClient(cfg),
		GuildRole:      NewGuildRoleClient(cfg),
		User:           NewUserClient(cfg),
		UserMembership: NewUserMembershipClient(cfg),
		YouTubeTalent:  NewYouTubeTalentClient(cfg),
	}, nil
}

// BeginTx returns a transactional client with specified options.
func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
	if _, ok := c.driver.(*txDriver); ok {
		return nil, errors.New("ent: cannot start a transaction within a transaction")
	}
	tx, err := c.driver.(interface {
		BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error)
	}).BeginTx(ctx, opts)
	if err != nil {
		return nil, fmt.Errorf("ent: starting a transaction: %w", err)
	}
	cfg := c.config
	cfg.driver = &txDriver{tx: tx, drv: c.driver}
	return &Tx{
		ctx:            ctx,
		config:         cfg,
		Guild:          NewGuildClient(cfg),
		GuildRole:      NewGuildRoleClient(cfg),
		User:           NewUserClient(cfg),
		UserMembership: NewUserMembershipClient(cfg),
		YouTubeTalent:  NewYouTubeTalentClient(cfg),
	}, nil
}

// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
//
//	client.Debug().
//		Guild.
//		Query().
//		Count(ctx)
func (c *Client) Debug() *Client {
	if c.debug {
		return c
	}
	cfg := c.config
	cfg.driver = dialect.Debug(c.driver, c.log)
	client := &Client{config: cfg}
	client.init()
	return client
}

// Close closes the database connection and prevents new queries from starting.
func (c *Client) Close() error {
	return c.driver.Close()
}

// Use adds the mutation hooks to all the entity clients.
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
func (c *Client) Use(hooks ...Hook) {
	c.Guild.Use(hooks...)
	c.GuildRole.Use(hooks...)
	c.User.Use(hooks...)
	c.UserMembership.Use(hooks...)
	c.YouTubeTalent.Use(hooks...)
}

// Intercept adds the query interceptors to all the entity clients.
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
func (c *Client) Intercept(interceptors ...Interceptor) {
	c.Guild.Intercept(interceptors...)
	c.GuildRole.Intercept(interceptors...)
	c.User.Intercept(interceptors...)
	c.UserMembership.Intercept(interceptors...)
	c.YouTubeTalent.Intercept(interceptors...)
}

// Mutate implements the ent.Mutator interface.
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
	switch m := m.(type) {
	case *GuildMutation:
		return c.Guild.mutate(ctx, m)
	case *GuildRoleMutation:
		return c.GuildRole.mutate(ctx, m)
	case *UserMutation:
		return c.User.mutate(ctx, m)
	case *UserMembershipMutation:
		return c.UserMembership.mutate(ctx, m)
	case *YouTubeTalentMutation:
		return c.YouTubeTalent.mutate(ctx, m)
	default:
		return nil, fmt.Errorf("ent: unknown mutation type %T", m)
	}
}

// GuildClient is a client for the Guild schema.
type GuildClient struct {
	config
}

// NewGuildClient returns a client for the Guild from the given config.
func NewGuildClient(c config) *GuildClient {
	return &GuildClient{config: c}
}

// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `guild.Hooks(f(g(h())))`.
func (c *GuildClient) Use(hooks ...Hook) {
	c.hooks.Guild = append(c.hooks.Guild, hooks...)
}

// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `guild.Intercept(f(g(h())))`.
func (c *GuildClient) Intercept(interceptors ...Interceptor) {
	c.inters.Guild = append(c.inters.Guild, interceptors...)
}

// Create returns a builder for creating a Guild entity.
func (c *GuildClient) Create() *GuildCreate {
	mutation := newGuildMutation(c.config, OpCreate)
	return &GuildCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// CreateBulk returns a builder for creating a bulk of Guild entities.
func (c *GuildClient) CreateBulk(builders ...*GuildCreate) *GuildCreateBulk {
	return &GuildCreateBulk{config: c.config, builders: builders}
}

// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *GuildClient) MapCreateBulk(slice any, setFunc func(*GuildCreate, int)) *GuildCreateBulk {
	rv := reflect.ValueOf(slice)
	if rv.Kind() != reflect.Slice {
		return &GuildCreateBulk{err: fmt.Errorf("calling to GuildClient.MapCreateBulk with wrong type %T, need slice", slice)}
	}
	builders := make([]*GuildCreate, rv.Len())
	for i := 0; i < rv.Len(); i++ {
		builders[i] = c.Create()
		setFunc(builders[i], i)
	}
	return &GuildCreateBulk{config: c.config, builders: builders}
}

// Update returns an update builder for Guild.
func (c *GuildClient) Update() *GuildUpdate {
	mutation := newGuildMutation(c.config, OpUpdate)
	return &GuildUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOne returns an update builder for the given entity.
func (c *GuildClient) UpdateOne(gu *Guild) *GuildUpdateOne {
	mutation := newGuildMutation(c.config, OpUpdateOne, withGuild(gu))
	return &GuildUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOneID returns an update builder for the given id.
func (c *GuildClient) UpdateOneID(id uint64) *GuildUpdateOne {
	mutation := newGuildMutation(c.config, OpUpdateOne, withGuildID(id))
	return &GuildUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// Delete returns a delete builder for Guild.
func (c *GuildClient) Delete() *GuildDelete {
	mutation := newGuildMutation(c.config, OpDelete)
	return &GuildDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// DeleteOne returns a builder for deleting the given entity.
func (c *GuildClient) DeleteOne(gu *Guild) *GuildDeleteOne {
	return c.DeleteOneID(gu.ID)
}

// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *GuildClient) DeleteOneID(id uint64) *GuildDeleteOne {
	builder := c.Delete().Where(guild.ID(id))
	builder.mutation.id = &id
	builder.mutation.op = OpDeleteOne
	return &GuildDeleteOne{builder}
}

// Query returns a query builder for Guild.
func (c *GuildClient) Query() *GuildQuery {
	return &GuildQuery{
		config: c.config,
		ctx:    &QueryContext{Type: TypeGuild},
		inters: c.Interceptors(),
	}
}

// Get returns a Guild entity by its id.
func (c *GuildClient) Get(ctx context.Context, id uint64) (*Guild, error) {
	return c.Query().Where(guild.ID(id)).Only(ctx)
}

// GetX is like Get, but panics if an error occurs.
func (c *GuildClient) GetX(ctx context.Context, id uint64) *Guild {
	obj, err := c.Get(ctx, id)
	if err != nil {
		panic(err)
	}
	return obj
}

// QueryMembers queries the members edge of a Guild.
func (c *GuildClient) QueryMembers(gu *Guild) *UserQuery {
	query := (&UserClient{config: c.config}).Query()
	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
		id := gu.ID
		step := sqlgraph.NewStep(
			sqlgraph.From(guild.Table, guild.FieldID, id),
			sqlgraph.To(user.Table, user.FieldID),
			sqlgraph.Edge(sqlgraph.M2M, false, guild.MembersTable, guild.MembersPrimaryKey...),
		)
		fromV = sqlgraph.Neighbors(gu.driver.Dialect(), step)
		return fromV, nil
	}
	return query
}

// QueryAdmins queries the admins edge of a Guild.
func (c *GuildClient) QueryAdmins(gu *Guild) *UserQuery {
	query := (&UserClient{config: c.config}).Query()
	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
		id := gu.ID
		step := sqlgraph.NewStep(
			sqlgraph.From(guild.Table, guild.FieldID, id),
			sqlgraph.To(user.Table, user.FieldID),
			sqlgraph.Edge(sqlgraph.M2M, false, guild.AdminsTable, guild.AdminsPrimaryKey...),
		)
		fromV = sqlgraph.Neighbors(gu.driver.Dialect(), step)
		return fromV, nil
	}
	return query
}

// QueryRoles queries the roles edge of a Guild.
func (c *GuildClient) QueryRoles(gu *Guild) *GuildRoleQuery {
	query := (&GuildRoleClient{config: c.config}).Query()
	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
		id := gu.ID
		step := sqlgraph.NewStep(
			sqlgraph.From(guild.Table, guild.FieldID, id),
			sqlgraph.To(guildrole.Table, guildrole.FieldID),
			sqlgraph.Edge(sqlgraph.O2M, false, guild.RolesTable, guild.RolesColumn),
		)
		fromV = sqlgraph.Neighbors(gu.driver.Dialect(), step)
		return fromV, nil
	}
	return query
}

// QueryYoutubeTalents queries the youtube_talents edge of a Guild.
func (c *GuildClient) QueryYoutubeTalents(gu *Guild) *YouTubeTalentQuery {
	query := (&YouTubeTalentClient{config: c.config}).Query()
	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
		id := gu.ID
		step := sqlgraph.NewStep(
			sqlgraph.From(guild.Table, guild.FieldID, id),
			sqlgraph.To(youtubetalent.Table, youtubetalent.FieldID),
			sqlgraph.Edge(sqlgraph.M2M, true, guild.YoutubeTalentsTable, guild.YoutubeTalentsPrimaryKey...),
		)
		fromV = sqlgraph.Neighbors(gu.driver.Dialect(), step)
		return fromV, nil
	}
	return query
}

// Hooks returns the client hooks.
func (c *GuildClient) Hooks() []Hook {
	return c.hooks.Guild
}

// Interceptors returns the client interceptors.
func (c *GuildClient) Interceptors() []Interceptor {
	return c.inters.Guild
}

func (c *GuildClient) mutate(ctx context.Context, m *GuildMutation) (Value, error) {
	switch m.Op() {
	case OpCreate:
		return (&GuildCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdate:
		return (&GuildUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdateOne:
		return (&GuildUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpDelete, OpDeleteOne:
		return (&GuildDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
	default:
		return nil, fmt.Errorf("ent: unknown Guild mutation op: %q", m.Op())
	}
}

// GuildRoleClient is a client for the GuildRole schema.
type GuildRoleClient struct {
	config
}

// NewGuildRoleClient returns a client for the GuildRole from the given config.
func NewGuildRoleClient(c config) *GuildRoleClient {
	return &GuildRoleClient{config: c}
}

// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `guildrole.Hooks(f(g(h())))`.
func (c *GuildRoleClient) Use(hooks ...Hook) {
	c.hooks.GuildRole = append(c.hooks.GuildRole, hooks...)
}

// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `guildrole.Intercept(f(g(h())))`.
func (c *GuildRoleClient) Intercept(interceptors ...Interceptor) {
	c.inters.GuildRole = append(c.inters.GuildRole, interceptors...)
}

// Create returns a builder for creating a GuildRole entity.
func (c *GuildRoleClient) Create() *GuildRoleCreate {
	mutation := newGuildRoleMutation(c.config, OpCreate)
	return &GuildRoleCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// CreateBulk returns a builder for creating a bulk of GuildRole entities.
func (c *GuildRoleClient) CreateBulk(builders ...*GuildRoleCreate) *GuildRoleCreateBulk {
	return &GuildRoleCreateBulk{config: c.config, builders: builders}
}

// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *GuildRoleClient) MapCreateBulk(slice any, setFunc func(*GuildRoleCreate, int)) *GuildRoleCreateBulk {
	rv := reflect.ValueOf(slice)
	if rv.Kind() != reflect.Slice {
		return &GuildRoleCreateBulk{err: fmt.Errorf("calling to GuildRoleClient.MapCreateBulk with wrong type %T, need slice", slice)}
	}
	builders := make([]*GuildRoleCreate, rv.Len())
	for i := 0; i < rv.Len(); i++ {
		builders[i] = c.Create()
		setFunc(builders[i], i)
	}
	return &GuildRoleCreateBulk{config: c.config, builders: builders}
}

// Update returns an update builder for GuildRole.
func (c *GuildRoleClient) Update() *GuildRoleUpdate {
	mutation := newGuildRoleMutation(c.config, OpUpdate)
	return &GuildRoleUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOne returns an update builder for the given entity.
func (c *GuildRoleClient) UpdateOne(gr *GuildRole) *GuildRoleUpdateOne {
	mutation := newGuildRoleMutation(c.config, OpUpdateOne, withGuildRole(gr))
	return &GuildRoleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOneID returns an update builder for the given id.
func (c *GuildRoleClient) UpdateOneID(id uint64) *GuildRoleUpdateOne {
	mutation := newGuildRoleMutation(c.config, OpUpdateOne, withGuildRoleID(id))
	return &GuildRoleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// Delete returns a delete builder for GuildRole.
func (c *GuildRoleClient) Delete() *GuildRoleDelete {
	mutation := newGuildRoleMutation(c.config, OpDelete)
	return &GuildRoleDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// DeleteOne returns a builder for deleting the given entity.
func (c *GuildRoleClient) DeleteOne(gr *GuildRole) *GuildRoleDeleteOne {
	return c.DeleteOneID(gr.ID)
}

// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *GuildRoleClient) DeleteOneID(id uint64) *GuildRoleDeleteOne {
	builder := c.Delete().Where(guildrole.ID(id))
	builder.mutation.id = &id
	builder.mutation.op = OpDeleteOne
	return &GuildRoleDeleteOne{builder}
}

// Query returns a query builder for GuildRole.
func (c *GuildRoleClient) Query() *GuildRoleQuery {
	return &GuildRoleQuery{
		config: c.config,
		ctx:    &QueryContext{Type: TypeGuildRole},
		inters: c.Interceptors(),
	}
}

// Get returns a GuildRole entity by its id.
func (c *GuildRoleClient) Get(ctx context.Context, id uint64) (*GuildRole, error) {
	return c.Query().Where(guildrole.ID(id)).Only(ctx)
}

// GetX is like Get, but panics if an error occurs.
func (c *GuildRoleClient) GetX(ctx context.Context, id uint64) *GuildRole {
	obj, err := c.Get(ctx, id)
	if err != nil {
		panic(err)
	}
	return obj
}

// QueryGuild queries the guild edge of a GuildRole.
func (c *GuildRoleClient) QueryGuild(gr *GuildRole) *GuildQuery {
	query := (&GuildClient{config: c.config}).Query()
	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
		id := gr.ID
		step := sqlgraph.NewStep(
			sqlgraph.From(guildrole.Table, guildrole.FieldID, id),
			sqlgraph.To(guild.Table, guild.FieldID),
			sqlgraph.Edge(sqlgraph.M2O, true, guildrole.GuildTable, guildrole.GuildColumn),
		)
		fromV = sqlgraph.Neighbors(gr.driver.Dialect(), step)
		return fromV, nil
	}
	return query
}

// QueryUserMemberships queries the user_memberships edge of a GuildRole.
func (c *GuildRoleClient) QueryUserMemberships(gr *GuildRole) *UserMembershipQuery {
	query := (&UserMembershipClient{config: c.config}).Query()
	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
		id := gr.ID
		step := sqlgraph.NewStep(
			sqlgraph.From(guildrole.Table, guildrole.FieldID, id),
			sqlgraph.To(usermembership.Table, usermembership.FieldID),
			sqlgraph.Edge(sqlgraph.M2M, true, guildrole.UserMembershipsTable, guildrole.UserMembershipsPrimaryKey...),
		)
		fromV = sqlgraph.Neighbors(gr.driver.Dialect(), step)
		return fromV, nil
	}
	return query
}

// QueryTalent queries the talent edge of a GuildRole.
func (c *GuildRoleClient) QueryTalent(gr *GuildRole) *YouTubeTalentQuery {
	query := (&YouTubeTalentClient{config: c.config}).Query()
	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
		id := gr.ID
		step := sqlgraph.NewStep(
			sqlgraph.From(guildrole.Table, guildrole.FieldID, id),
			sqlgraph.To(youtubetalent.Table, youtubetalent.FieldID),
			sqlgraph.Edge(sqlgraph.M2O, true, guildrole.TalentTable, guildrole.TalentColumn),
		)
		fromV = sqlgraph.Neighbors(gr.driver.Dialect(), step)
		return fromV, nil
	}
	return query
}

// Hooks returns the client hooks.
func (c *GuildRoleClient) Hooks() []Hook {
	return c.hooks.GuildRole
}

// Interceptors returns the client interceptors.
func (c *GuildRoleClient) Interceptors() []Interceptor {
	return c.inters.GuildRole
}

func (c *GuildRoleClient) mutate(ctx context.Context, m *GuildRoleMutation) (Value, error) {
	switch m.Op() {
	case OpCreate:
		return (&GuildRoleCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdate:
		return (&GuildRoleUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdateOne:
		return (&GuildRoleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpDelete, OpDeleteOne:
		return (&GuildRoleDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
	default:
		return nil, fmt.Errorf("ent: unknown GuildRole mutation op: %q", m.Op())
	}
}

// UserClient is a client for the User schema.
type UserClient struct {
	config
}

// NewUserClient returns a client for the User from the given config.
func NewUserClient(c config) *UserClient {
	return &UserClient{config: c}
}

// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `user.Hooks(f(g(h())))`.
func (c *UserClient) Use(hooks ...Hook) {
	c.hooks.User = append(c.hooks.User, hooks...)
}

// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `user.Intercept(f(g(h())))`.
func (c *UserClient) Intercept(interceptors ...Interceptor) {
	c.inters.User = append(c.inters.User, interceptors...)
}

// Create returns a builder for creating a User entity.
func (c *UserClient) Create() *UserCreate {
	mutation := newUserMutation(c.config, OpCreate)
	return &UserCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// CreateBulk returns a builder for creating a bulk of User entities.
func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk {
	return &UserCreateBulk{config: c.config, builders: builders}
}

// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk {
	rv := reflect.ValueOf(slice)
	if rv.Kind() != reflect.Slice {
		return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)}
	}
	builders := make([]*UserCreate, rv.Len())
	for i := 0; i < rv.Len(); i++ {
		builders[i] = c.Create()
		setFunc(builders[i], i)
	}
	return &UserCreateBulk{config: c.config, builders: builders}
}

// Update returns an update builder for User.
func (c *UserClient) Update() *UserUpdate {
	mutation := newUserMutation(c.config, OpUpdate)
	return &UserUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOne returns an update builder for the given entity.
func (c *UserClient) UpdateOne(u *User) *UserUpdateOne {
	mutation := newUserMutation(c.config, OpUpdateOne, withUser(u))
	return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOneID returns an update builder for the given id.
func (c *UserClient) UpdateOneID(id uint64) *UserUpdateOne {
	mutation := newUserMutation(c.config, OpUpdateOne, withUserID(id))
	return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// Delete returns a delete builder for User.
func (c *UserClient) Delete() *UserDelete {
	mutation := newUserMutation(c.config, OpDelete)
	return &UserDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// DeleteOne returns a builder for deleting the given entity.
func (c *UserClient) DeleteOne(u *User) *UserDeleteOne {
	return c.DeleteOneID(u.ID)
}

// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *UserClient) DeleteOneID(id uint64) *UserDeleteOne {
	builder := c.Delete().Where(user.ID(id))
	builder.mutation.id = &id
	builder.mutation.op = OpDeleteOne
	return &UserDeleteOne{builder}
}

// Query returns a query builder for User.
func (c *UserClient) Query() *UserQuery {
	return &UserQuery{
		config: c.config,
		ctx:    &QueryContext{Type: TypeUser},
		inters: c.Interceptors(),
	}
}

// Get returns a User entity by its id.
func (c *UserClient) Get(ctx context.Context, id uint64) (*User, error) {
	return c.Query().Where(user.ID(id)).Only(ctx)
}

// GetX is like Get, but panics if an error occurs.
func (c *UserClient) GetX(ctx context.Context, id uint64) *User {
	obj, err := c.Get(ctx, id)
	if err != nil {
		panic(err)
	}
	return obj
}

// QueryGuilds queries the guilds edge of a User.
func (c *UserClient) QueryGuilds(u *User) *GuildQuery {
	query := (&GuildClient{config: c.config}).Query()
	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
		id := u.ID
		step := sqlgraph.NewStep(
			sqlgraph.From(user.Table, user.FieldID, id),
			sqlgraph.To(guild.Table, guild.FieldID),
			sqlgraph.Edge(sqlgraph.M2M, true, user.GuildsTable, user.GuildsPrimaryKey...),
		)
		fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
		return fromV, nil
	}
	return query
}

// QueryGuildsAdmin queries the guilds_admin edge of a User.
func (c *UserClient) QueryGuildsAdmin(u *User) *GuildQuery {
	query := (&GuildClient{config: c.config}).Query()
	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
		id := u.ID
		step := sqlgraph.NewStep(
			sqlgraph.From(user.Table, user.FieldID, id),
			sqlgraph.To(guild.Table, guild.FieldID),
			sqlgraph.Edge(sqlgraph.M2M, true, user.GuildsAdminTable, user.GuildsAdminPrimaryKey...),
		)
		fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
		return fromV, nil
	}
	return query
}

// QueryMemberships queries the memberships edge of a User.
func (c *UserClient) QueryMemberships(u *User) *UserMembershipQuery {
	query := (&UserMembershipClient{config: c.config}).Query()
	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
		id := u.ID
		step := sqlgraph.NewStep(
			sqlgraph.From(user.Table, user.FieldID, id),
			sqlgraph.To(usermembership.Table, usermembership.FieldID),
			sqlgraph.Edge(sqlgraph.O2M, false, user.MembershipsTable, user.MembershipsColumn),
		)
		fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
		return fromV, nil
	}
	return query
}

// Hooks returns the client hooks.
func (c *UserClient) Hooks() []Hook {
	return c.hooks.User
}

// Interceptors returns the client interceptors.
func (c *UserClient) Interceptors() []Interceptor {
	return c.inters.User
}

func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) {
	switch m.Op() {
	case OpCreate:
		return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdate:
		return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdateOne:
		return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpDelete, OpDeleteOne:
		return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
	default:
		return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op())
	}
}

// UserMembershipClient is a client for the UserMembership schema.
type UserMembershipClient struct {
	config
}

// NewUserMembershipClient returns a client for the UserMembership from the given config.
func NewUserMembershipClient(c config) *UserMembershipClient {
	return &UserMembershipClient{config: c}
}

// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `usermembership.Hooks(f(g(h())))`.
func (c *UserMembershipClient) Use(hooks ...Hook) {
	c.hooks.UserMembership = append(c.hooks.UserMembership, hooks...)
}

// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `usermembership.Intercept(f(g(h())))`.
func (c *UserMembershipClient) Intercept(interceptors ...Interceptor) {
	c.inters.UserMembership = append(c.inters.UserMembership, interceptors...)
}

// Create returns a builder for creating a UserMembership entity.
func (c *UserMembershipClient) Create() *UserMembershipCreate {
	mutation := newUserMembershipMutation(c.config, OpCreate)
	return &UserMembershipCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// CreateBulk returns a builder for creating a bulk of UserMembership entities.
func (c *UserMembershipClient) CreateBulk(builders ...*UserMembershipCreate) *UserMembershipCreateBulk {
	return &UserMembershipCreateBulk{config: c.config, builders: builders}
}

// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *UserMembershipClient) MapCreateBulk(slice any, setFunc func(*UserMembershipCreate, int)) *UserMembershipCreateBulk {
	rv := reflect.ValueOf(slice)
	if rv.Kind() != reflect.Slice {
		return &UserMembershipCreateBulk{err: fmt.Errorf("calling to UserMembershipClient.MapCreateBulk with wrong type %T, need slice", slice)}
	}
	builders := make([]*UserMembershipCreate, rv.Len())
	for i := 0; i < rv.Len(); i++ {
		builders[i] = c.Create()
		setFunc(builders[i], i)
	}
	return &UserMembershipCreateBulk{config: c.config, builders: builders}
}

// Update returns an update builder for UserMembership.
func (c *UserMembershipClient) Update() *UserMembershipUpdate {
	mutation := newUserMembershipMutation(c.config, OpUpdate)
	return &UserMembershipUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOne returns an update builder for the given entity.
func (c *UserMembershipClient) UpdateOne(um *UserMembership) *UserMembershipUpdateOne {
	mutation := newUserMembershipMutation(c.config, OpUpdateOne, withUserMembership(um))
	return &UserMembershipUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOneID returns an update builder for the given id.
func (c *UserMembershipClient) UpdateOneID(id int) *UserMembershipUpdateOne {
	mutation := newUserMembershipMutation(c.config, OpUpdateOne, withUserMembershipID(id))
	return &UserMembershipUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// Delete returns a delete builder for UserMembership.
func (c *UserMembershipClient) Delete() *UserMembershipDelete {
	mutation := newUserMembershipMutation(c.config, OpDelete)
	return &UserMembershipDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// DeleteOne returns a builder for deleting the given entity.
func (c *UserMembershipClient) DeleteOne(um *UserMembership) *UserMembershipDeleteOne {
	return c.DeleteOneID(um.ID)
}

// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *UserMembershipClient) DeleteOneID(id int) *UserMembershipDeleteOne {
	builder := c.Delete().Where(usermembership.ID(id))
	builder.mutation.id = &id
	builder.mutation.op = OpDeleteOne
	return &UserMembershipDeleteOne{builder}
}

// Query returns a query builder for UserMembership.
func (c *UserMembershipClient) Query() *UserMembershipQuery {
	return &UserMembershipQuery{
		config: c.config,
		ctx:    &QueryContext{Type: TypeUserMembership},
		inters: c.Interceptors(),
	}
}

// Get returns a UserMembership entity by its id.
func (c *UserMembershipClient) Get(ctx context.Context, id int) (*UserMembership, error) {
	return c.Query().Where(usermembership.ID(id)).Only(ctx)
}

// GetX is like Get, but panics if an error occurs.
func (c *UserMembershipClient) GetX(ctx context.Context, id int) *UserMembership {
	obj, err := c.Get(ctx, id)
	if err != nil {
		panic(err)
	}
	return obj
}

// QueryUser queries the user edge of a UserMembership.
func (c *UserMembershipClient) QueryUser(um *UserMembership) *UserQuery {
	query := (&UserClient{config: c.config}).Query()
	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
		id := um.ID
		step := sqlgraph.NewStep(
			sqlgraph.From(usermembership.Table, usermembership.FieldID, id),
			sqlgraph.To(user.Table, user.FieldID),
			sqlgraph.Edge(sqlgraph.M2O, true, usermembership.UserTable, usermembership.UserColumn),
		)
		fromV = sqlgraph.Neighbors(um.driver.Dialect(), step)
		return fromV, nil
	}
	return query
}

// QueryYoutubeTalent queries the youtube_talent edge of a UserMembership.
func (c *UserMembershipClient) QueryYoutubeTalent(um *UserMembership) *YouTubeTalentQuery {
	query := (&YouTubeTalentClient{config: c.config}).Query()
	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
		id := um.ID
		step := sqlgraph.NewStep(
			sqlgraph.From(usermembership.Table, usermembership.FieldID, id),
			sqlgraph.To(youtubetalent.Table, youtubetalent.FieldID),
			sqlgraph.Edge(sqlgraph.M2O, false, usermembership.YoutubeTalentTable, usermembership.YoutubeTalentColumn),
		)
		fromV = sqlgraph.Neighbors(um.driver.Dialect(), step)
		return fromV, nil
	}
	return query
}

// QueryRoles queries the roles edge of a UserMembership.
func (c *UserMembershipClient) QueryRoles(um *UserMembership) *GuildRoleQuery {
	query := (&GuildRoleClient{config: c.config}).Query()
	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
		id := um.ID
		step := sqlgraph.NewStep(
			sqlgraph.From(usermembership.Table, usermembership.FieldID, id),
			sqlgraph.To(guildrole.Table, guildrole.FieldID),
			sqlgraph.Edge(sqlgraph.M2M, false, usermembership.RolesTable, usermembership.RolesPrimaryKey...),
		)
		fromV = sqlgraph.Neighbors(um.driver.Dialect(), step)
		return fromV, nil
	}
	return query
}

// Hooks returns the client hooks.
func (c *UserMembershipClient) Hooks() []Hook {
	return c.hooks.UserMembership
}

// Interceptors returns the client interceptors.
func (c *UserMembershipClient) Interceptors() []Interceptor {
	return c.inters.UserMembership
}

func (c *UserMembershipClient) mutate(ctx context.Context, m *UserMembershipMutation) (Value, error) {
	switch m.Op() {
	case OpCreate:
		return (&UserMembershipCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdate:
		return (&UserMembershipUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdateOne:
		return (&UserMembershipUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpDelete, OpDeleteOne:
		return (&UserMembershipDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
	default:
		return nil, fmt.Errorf("ent: unknown UserMembership mutation op: %q", m.Op())
	}
}

// YouTubeTalentClient is a client for the YouTubeTalent schema.
type YouTubeTalentClient struct {
	config
}

// NewYouTubeTalentClient returns a client for the YouTubeTalent from the given config.
func NewYouTubeTalentClient(c config) *YouTubeTalentClient {
	return &YouTubeTalentClient{config: c}
}

// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `youtubetalent.Hooks(f(g(h())))`.
func (c *YouTubeTalentClient) Use(hooks ...Hook) {
	c.hooks.YouTubeTalent = append(c.hooks.YouTubeTalent, hooks...)
}

// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `youtubetalent.Intercept(f(g(h())))`.
func (c *YouTubeTalentClient) Intercept(interceptors ...Interceptor) {
	c.inters.YouTubeTalent = append(c.inters.YouTubeTalent, interceptors...)
}

// Create returns a builder for creating a YouTubeTalent entity.
func (c *YouTubeTalentClient) Create() *YouTubeTalentCreate {
	mutation := newYouTubeTalentMutation(c.config, OpCreate)
	return &YouTubeTalentCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// CreateBulk returns a builder for creating a bulk of YouTubeTalent entities.
func (c *YouTubeTalentClient) CreateBulk(builders ...*YouTubeTalentCreate) *YouTubeTalentCreateBulk {
	return &YouTubeTalentCreateBulk{config: c.config, builders: builders}
}

// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *YouTubeTalentClient) MapCreateBulk(slice any, setFunc func(*YouTubeTalentCreate, int)) *YouTubeTalentCreateBulk {
	rv := reflect.ValueOf(slice)
	if rv.Kind() != reflect.Slice {
		return &YouTubeTalentCreateBulk{err: fmt.Errorf("calling to YouTubeTalentClient.MapCreateBulk with wrong type %T, need slice", slice)}
	}
	builders := make([]*YouTubeTalentCreate, rv.Len())
	for i := 0; i < rv.Len(); i++ {
		builders[i] = c.Create()
		setFunc(builders[i], i)
	}
	return &YouTubeTalentCreateBulk{config: c.config, builders: builders}
}

// Update returns an update builder for YouTubeTalent.
func (c *YouTubeTalentClient) Update() *YouTubeTalentUpdate {
	mutation := newYouTubeTalentMutation(c.config, OpUpdate)
	return &YouTubeTalentUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOne returns an update builder for the given entity.
func (c *YouTubeTalentClient) UpdateOne(ytt *YouTubeTalent) *YouTubeTalentUpdateOne {
	mutation := newYouTubeTalentMutation(c.config, OpUpdateOne, withYouTubeTalent(ytt))
	return &YouTubeTalentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOneID returns an update builder for the given id.
func (c *YouTubeTalentClient) UpdateOneID(id string) *YouTubeTalentUpdateOne {
	mutation := newYouTubeTalentMutation(c.config, OpUpdateOne, withYouTubeTalentID(id))
	return &YouTubeTalentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// Delete returns a delete builder for YouTubeTalent.
func (c *YouTubeTalentClient) Delete() *YouTubeTalentDelete {
	mutation := newYouTubeTalentMutation(c.config, OpDelete)
	return &YouTubeTalentDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// DeleteOne returns a builder for deleting the given entity.
func (c *YouTubeTalentClient) DeleteOne(ytt *YouTubeTalent) *YouTubeTalentDeleteOne {
	return c.DeleteOneID(ytt.ID)
}

// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *YouTubeTalentClient) DeleteOneID(id string) *YouTubeTalentDeleteOne {
	builder := c.Delete().Where(youtubetalent.ID(id))
	builder.mutation.id = &id
	builder.mutation.op = OpDeleteOne
	return &YouTubeTalentDeleteOne{builder}
}

// Query returns a query builder for YouTubeTalent.
func (c *YouTubeTalentClient) Query() *YouTubeTalentQuery {
	return &YouTubeTalentQuery{
		config: c.config,
		ctx:    &QueryContext{Type: TypeYouTubeTalent},
		inters: c.Interceptors(),
	}
}

// Get returns a YouTubeTalent entity by its id.
func (c *YouTubeTalentClient) Get(ctx context.Context, id string) (*YouTubeTalent, error) {
	return c.Query().Where(youtubetalent.ID(id)).Only(ctx)
}

// GetX is like Get, but panics if an error occurs.
func (c *YouTubeTalentClient) GetX(ctx context.Context, id string) *YouTubeTalent {
	obj, err := c.Get(ctx, id)
	if err != nil {
		panic(err)
	}
	return obj
}

// QueryGuilds queries the guilds edge of a YouTubeTalent.
func (c *YouTubeTalentClient) QueryGuilds(ytt *YouTubeTalent) *GuildQuery {
	query := (&GuildClient{config: c.config}).Query()
	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
		id := ytt.ID
		step := sqlgraph.NewStep(
			sqlgraph.From(youtubetalent.Table, youtubetalent.FieldID, id),
			sqlgraph.To(guild.Table, guild.FieldID),
			sqlgraph.Edge(sqlgraph.M2M, false, youtubetalent.GuildsTable, youtubetalent.GuildsPrimaryKey...),
		)
		fromV = sqlgraph.Neighbors(ytt.driver.Dialect(), step)
		return fromV, nil
	}
	return query
}

// QueryRoles queries the roles edge of a YouTubeTalent.
func (c *YouTubeTalentClient) QueryRoles(ytt *YouTubeTalent) *GuildRoleQuery {
	query := (&GuildRoleClient{config: c.config}).Query()
	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
		id := ytt.ID
		step := sqlgraph.NewStep(
			sqlgraph.From(youtubetalent.Table, youtubetalent.FieldID, id),
			sqlgraph.To(guildrole.Table, guildrole.FieldID),
			sqlgraph.Edge(sqlgraph.O2M, false, youtubetalent.RolesTable, youtubetalent.RolesColumn),
		)
		fromV = sqlgraph.Neighbors(ytt.driver.Dialect(), step)
		return fromV, nil
	}
	return query
}

// QueryMemberships queries the memberships edge of a YouTubeTalent.
func (c *YouTubeTalentClient) QueryMemberships(ytt *YouTubeTalent) *UserMembershipQuery {
	query := (&UserMembershipClient{config: c.config}).Query()
	query.path = func(context.Context) (fromV *sql.Selector, _ error) {
		id := ytt.ID
		step := sqlgraph.NewStep(
			sqlgraph.From(youtubetalent.Table, youtubetalent.FieldID, id),
			sqlgraph.To(usermembership.Table, usermembership.FieldID),
			sqlgraph.Edge(sqlgraph.O2M, true, youtubetalent.MembershipsTable, youtubetalent.MembershipsColumn),
		)
		fromV = sqlgraph.Neighbors(ytt.driver.Dialect(), step)
		return fromV, nil
	}
	return query
}

// Hooks returns the client hooks.
func (c *YouTubeTalentClient) Hooks() []Hook {
	return c.hooks.YouTubeTalent
}

// Interceptors returns the client interceptors.
func (c *YouTubeTalentClient) Interceptors() []Interceptor {
	return c.inters.YouTubeTalent
}

func (c *YouTubeTalentClient) mutate(ctx context.Context, m *YouTubeTalentMutation) (Value, error) {
	switch m.Op() {
	case OpCreate:
		return (&YouTubeTalentCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdate:
		return (&YouTubeTalentUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdateOne:
		return (&YouTubeTalentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpDelete, OpDeleteOne:
		return (&YouTubeTalentDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
	default:
		return nil, fmt.Errorf("ent: unknown YouTubeTalent mutation op: %q", m.Op())
	}
}

// hooks and interceptors per client, for fast access.
type (
	hooks struct {
		Guild, GuildRole, User, UserMembership, YouTubeTalent []ent.Hook
	}
	inters struct {
		Guild, GuildRole, User, UserMembership, YouTubeTalent []ent.Interceptor
	}
)
