// Code generated by ent, DO NOT EDIT.

package serversitemicros

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

	"convert-server/domain/entity/serversitemicros/migrate"

	"convert-server/domain/entity/serversitemicros/docserverapp"
	"convert-server/domain/entity/serversitemicros/docservercallback"
	"convert-server/domain/entity/serversitemicros/docservergetproject"
	"convert-server/domain/entity/serversitemicros/docserverproject"

	"entgo.io/ent"
	"entgo.io/ent/dialect"
	"entgo.io/ent/dialect/sql"
)

// 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
	// DocServerApp is the client for interacting with the DocServerApp builders.
	DocServerApp *DocServerAppClient
	// DocServerCallback is the client for interacting with the DocServerCallback builders.
	DocServerCallback *DocServerCallbackClient
	// DocServerGetProject is the client for interacting with the DocServerGetProject builders.
	DocServerGetProject *DocServerGetProjectClient
	// DocServerProject is the client for interacting with the DocServerProject builders.
	DocServerProject *DocServerProjectClient
}

// 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.DocServerApp = NewDocServerAppClient(c.config)
	c.DocServerCallback = NewDocServerCallbackClient(c.config)
	c.DocServerGetProject = NewDocServerGetProjectClient(c.config)
	c.DocServerProject = NewDocServerProjectClient(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("serversitemicros: 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("serversitemicros: starting a transaction: %w", err)
	}
	cfg := c.config
	cfg.driver = tx
	return &Tx{
		ctx:                 ctx,
		config:              cfg,
		DocServerApp:        NewDocServerAppClient(cfg),
		DocServerCallback:   NewDocServerCallbackClient(cfg),
		DocServerGetProject: NewDocServerGetProjectClient(cfg),
		DocServerProject:    NewDocServerProjectClient(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,
		DocServerApp:        NewDocServerAppClient(cfg),
		DocServerCallback:   NewDocServerCallbackClient(cfg),
		DocServerGetProject: NewDocServerGetProjectClient(cfg),
		DocServerProject:    NewDocServerProjectClient(cfg),
	}, nil
}

// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
//
//	client.Debug().
//		DocServerApp.
//		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.DocServerApp.Use(hooks...)
	c.DocServerCallback.Use(hooks...)
	c.DocServerGetProject.Use(hooks...)
	c.DocServerProject.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.DocServerApp.Intercept(interceptors...)
	c.DocServerCallback.Intercept(interceptors...)
	c.DocServerGetProject.Intercept(interceptors...)
	c.DocServerProject.Intercept(interceptors...)
}

// Mutate implements the ent.Mutator interface.
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
	switch m := m.(type) {
	case *DocServerAppMutation:
		return c.DocServerApp.mutate(ctx, m)
	case *DocServerCallbackMutation:
		return c.DocServerCallback.mutate(ctx, m)
	case *DocServerGetProjectMutation:
		return c.DocServerGetProject.mutate(ctx, m)
	case *DocServerProjectMutation:
		return c.DocServerProject.mutate(ctx, m)
	default:
		return nil, fmt.Errorf("serversitemicros: unknown mutation type %T", m)
	}
}

// DocServerAppClient is a client for the DocServerApp schema.
type DocServerAppClient struct {
	config
}

// NewDocServerAppClient returns a client for the DocServerApp from the given config.
func NewDocServerAppClient(c config) *DocServerAppClient {
	return &DocServerAppClient{config: c}
}

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

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

// Create returns a builder for creating a DocServerApp entity.
func (c *DocServerAppClient) Create() *DocServerAppCreate {
	mutation := newDocServerAppMutation(c.config, OpCreate)
	return &DocServerAppCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// CreateBulk returns a builder for creating a bulk of DocServerApp entities.
func (c *DocServerAppClient) CreateBulk(builders ...*DocServerAppCreate) *DocServerAppCreateBulk {
	return &DocServerAppCreateBulk{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 *DocServerAppClient) MapCreateBulk(slice any, setFunc func(*DocServerAppCreate, int)) *DocServerAppCreateBulk {
	rv := reflect.ValueOf(slice)
	if rv.Kind() != reflect.Slice {
		return &DocServerAppCreateBulk{err: fmt.Errorf("calling to DocServerAppClient.MapCreateBulk with wrong type %T, need slice", slice)}
	}
	builders := make([]*DocServerAppCreate, rv.Len())
	for i := 0; i < rv.Len(); i++ {
		builders[i] = c.Create()
		setFunc(builders[i], i)
	}
	return &DocServerAppCreateBulk{config: c.config, builders: builders}
}

// Update returns an update builder for DocServerApp.
func (c *DocServerAppClient) Update() *DocServerAppUpdate {
	mutation := newDocServerAppMutation(c.config, OpUpdate)
	return &DocServerAppUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOne returns an update builder for the given entity.
func (c *DocServerAppClient) UpdateOne(dsa *DocServerApp) *DocServerAppUpdateOne {
	mutation := newDocServerAppMutation(c.config, OpUpdateOne, withDocServerApp(dsa))
	return &DocServerAppUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOneID returns an update builder for the given id.
func (c *DocServerAppClient) UpdateOneID(id int32) *DocServerAppUpdateOne {
	mutation := newDocServerAppMutation(c.config, OpUpdateOne, withDocServerAppID(id))
	return &DocServerAppUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// Delete returns a delete builder for DocServerApp.
func (c *DocServerAppClient) Delete() *DocServerAppDelete {
	mutation := newDocServerAppMutation(c.config, OpDelete)
	return &DocServerAppDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// DeleteOne returns a builder for deleting the given entity.
func (c *DocServerAppClient) DeleteOne(dsa *DocServerApp) *DocServerAppDeleteOne {
	return c.DeleteOneID(dsa.ID)
}

// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *DocServerAppClient) DeleteOneID(id int32) *DocServerAppDeleteOne {
	builder := c.Delete().Where(docserverapp.ID(id))
	builder.mutation.id = &id
	builder.mutation.op = OpDeleteOne
	return &DocServerAppDeleteOne{builder}
}

// Query returns a query builder for DocServerApp.
func (c *DocServerAppClient) Query() *DocServerAppQuery {
	return &DocServerAppQuery{
		config: c.config,
		ctx:    &QueryContext{Type: TypeDocServerApp},
		inters: c.Interceptors(),
	}
}

// Get returns a DocServerApp entity by its id.
func (c *DocServerAppClient) Get(ctx context.Context, id int32) (*DocServerApp, error) {
	return c.Query().Where(docserverapp.ID(id)).Only(ctx)
}

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

// Hooks returns the client hooks.
func (c *DocServerAppClient) Hooks() []Hook {
	hooks := c.hooks.DocServerApp
	return append(hooks[:len(hooks):len(hooks)], docserverapp.Hooks[:]...)
}

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

func (c *DocServerAppClient) mutate(ctx context.Context, m *DocServerAppMutation) (Value, error) {
	switch m.Op() {
	case OpCreate:
		return (&DocServerAppCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdate:
		return (&DocServerAppUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdateOne:
		return (&DocServerAppUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpDelete, OpDeleteOne:
		return (&DocServerAppDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
	default:
		return nil, fmt.Errorf("serversitemicros: unknown DocServerApp mutation op: %q", m.Op())
	}
}

// DocServerCallbackClient is a client for the DocServerCallback schema.
type DocServerCallbackClient struct {
	config
}

// NewDocServerCallbackClient returns a client for the DocServerCallback from the given config.
func NewDocServerCallbackClient(c config) *DocServerCallbackClient {
	return &DocServerCallbackClient{config: c}
}

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

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

// Create returns a builder for creating a DocServerCallback entity.
func (c *DocServerCallbackClient) Create() *DocServerCallbackCreate {
	mutation := newDocServerCallbackMutation(c.config, OpCreate)
	return &DocServerCallbackCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// CreateBulk returns a builder for creating a bulk of DocServerCallback entities.
func (c *DocServerCallbackClient) CreateBulk(builders ...*DocServerCallbackCreate) *DocServerCallbackCreateBulk {
	return &DocServerCallbackCreateBulk{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 *DocServerCallbackClient) MapCreateBulk(slice any, setFunc func(*DocServerCallbackCreate, int)) *DocServerCallbackCreateBulk {
	rv := reflect.ValueOf(slice)
	if rv.Kind() != reflect.Slice {
		return &DocServerCallbackCreateBulk{err: fmt.Errorf("calling to DocServerCallbackClient.MapCreateBulk with wrong type %T, need slice", slice)}
	}
	builders := make([]*DocServerCallbackCreate, rv.Len())
	for i := 0; i < rv.Len(); i++ {
		builders[i] = c.Create()
		setFunc(builders[i], i)
	}
	return &DocServerCallbackCreateBulk{config: c.config, builders: builders}
}

// Update returns an update builder for DocServerCallback.
func (c *DocServerCallbackClient) Update() *DocServerCallbackUpdate {
	mutation := newDocServerCallbackMutation(c.config, OpUpdate)
	return &DocServerCallbackUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOne returns an update builder for the given entity.
func (c *DocServerCallbackClient) UpdateOne(dsc *DocServerCallback) *DocServerCallbackUpdateOne {
	mutation := newDocServerCallbackMutation(c.config, OpUpdateOne, withDocServerCallback(dsc))
	return &DocServerCallbackUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOneID returns an update builder for the given id.
func (c *DocServerCallbackClient) UpdateOneID(id int32) *DocServerCallbackUpdateOne {
	mutation := newDocServerCallbackMutation(c.config, OpUpdateOne, withDocServerCallbackID(id))
	return &DocServerCallbackUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// Delete returns a delete builder for DocServerCallback.
func (c *DocServerCallbackClient) Delete() *DocServerCallbackDelete {
	mutation := newDocServerCallbackMutation(c.config, OpDelete)
	return &DocServerCallbackDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// DeleteOne returns a builder for deleting the given entity.
func (c *DocServerCallbackClient) DeleteOne(dsc *DocServerCallback) *DocServerCallbackDeleteOne {
	return c.DeleteOneID(dsc.ID)
}

// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *DocServerCallbackClient) DeleteOneID(id int32) *DocServerCallbackDeleteOne {
	builder := c.Delete().Where(docservercallback.ID(id))
	builder.mutation.id = &id
	builder.mutation.op = OpDeleteOne
	return &DocServerCallbackDeleteOne{builder}
}

// Query returns a query builder for DocServerCallback.
func (c *DocServerCallbackClient) Query() *DocServerCallbackQuery {
	return &DocServerCallbackQuery{
		config: c.config,
		ctx:    &QueryContext{Type: TypeDocServerCallback},
		inters: c.Interceptors(),
	}
}

// Get returns a DocServerCallback entity by its id.
func (c *DocServerCallbackClient) Get(ctx context.Context, id int32) (*DocServerCallback, error) {
	return c.Query().Where(docservercallback.ID(id)).Only(ctx)
}

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

// Hooks returns the client hooks.
func (c *DocServerCallbackClient) Hooks() []Hook {
	hooks := c.hooks.DocServerCallback
	return append(hooks[:len(hooks):len(hooks)], docservercallback.Hooks[:]...)
}

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

func (c *DocServerCallbackClient) mutate(ctx context.Context, m *DocServerCallbackMutation) (Value, error) {
	switch m.Op() {
	case OpCreate:
		return (&DocServerCallbackCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdate:
		return (&DocServerCallbackUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdateOne:
		return (&DocServerCallbackUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpDelete, OpDeleteOne:
		return (&DocServerCallbackDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
	default:
		return nil, fmt.Errorf("serversitemicros: unknown DocServerCallback mutation op: %q", m.Op())
	}
}

// DocServerGetProjectClient is a client for the DocServerGetProject schema.
type DocServerGetProjectClient struct {
	config
}

// NewDocServerGetProjectClient returns a client for the DocServerGetProject from the given config.
func NewDocServerGetProjectClient(c config) *DocServerGetProjectClient {
	return &DocServerGetProjectClient{config: c}
}

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

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

// Create returns a builder for creating a DocServerGetProject entity.
func (c *DocServerGetProjectClient) Create() *DocServerGetProjectCreate {
	mutation := newDocServerGetProjectMutation(c.config, OpCreate)
	return &DocServerGetProjectCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// CreateBulk returns a builder for creating a bulk of DocServerGetProject entities.
func (c *DocServerGetProjectClient) CreateBulk(builders ...*DocServerGetProjectCreate) *DocServerGetProjectCreateBulk {
	return &DocServerGetProjectCreateBulk{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 *DocServerGetProjectClient) MapCreateBulk(slice any, setFunc func(*DocServerGetProjectCreate, int)) *DocServerGetProjectCreateBulk {
	rv := reflect.ValueOf(slice)
	if rv.Kind() != reflect.Slice {
		return &DocServerGetProjectCreateBulk{err: fmt.Errorf("calling to DocServerGetProjectClient.MapCreateBulk with wrong type %T, need slice", slice)}
	}
	builders := make([]*DocServerGetProjectCreate, rv.Len())
	for i := 0; i < rv.Len(); i++ {
		builders[i] = c.Create()
		setFunc(builders[i], i)
	}
	return &DocServerGetProjectCreateBulk{config: c.config, builders: builders}
}

// Update returns an update builder for DocServerGetProject.
func (c *DocServerGetProjectClient) Update() *DocServerGetProjectUpdate {
	mutation := newDocServerGetProjectMutation(c.config, OpUpdate)
	return &DocServerGetProjectUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOne returns an update builder for the given entity.
func (c *DocServerGetProjectClient) UpdateOne(dsgp *DocServerGetProject) *DocServerGetProjectUpdateOne {
	mutation := newDocServerGetProjectMutation(c.config, OpUpdateOne, withDocServerGetProject(dsgp))
	return &DocServerGetProjectUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOneID returns an update builder for the given id.
func (c *DocServerGetProjectClient) UpdateOneID(id int32) *DocServerGetProjectUpdateOne {
	mutation := newDocServerGetProjectMutation(c.config, OpUpdateOne, withDocServerGetProjectID(id))
	return &DocServerGetProjectUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// Delete returns a delete builder for DocServerGetProject.
func (c *DocServerGetProjectClient) Delete() *DocServerGetProjectDelete {
	mutation := newDocServerGetProjectMutation(c.config, OpDelete)
	return &DocServerGetProjectDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// DeleteOne returns a builder for deleting the given entity.
func (c *DocServerGetProjectClient) DeleteOne(dsgp *DocServerGetProject) *DocServerGetProjectDeleteOne {
	return c.DeleteOneID(dsgp.ID)
}

// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *DocServerGetProjectClient) DeleteOneID(id int32) *DocServerGetProjectDeleteOne {
	builder := c.Delete().Where(docservergetproject.ID(id))
	builder.mutation.id = &id
	builder.mutation.op = OpDeleteOne
	return &DocServerGetProjectDeleteOne{builder}
}

// Query returns a query builder for DocServerGetProject.
func (c *DocServerGetProjectClient) Query() *DocServerGetProjectQuery {
	return &DocServerGetProjectQuery{
		config: c.config,
		ctx:    &QueryContext{Type: TypeDocServerGetProject},
		inters: c.Interceptors(),
	}
}

// Get returns a DocServerGetProject entity by its id.
func (c *DocServerGetProjectClient) Get(ctx context.Context, id int32) (*DocServerGetProject, error) {
	return c.Query().Where(docservergetproject.ID(id)).Only(ctx)
}

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

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

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

func (c *DocServerGetProjectClient) mutate(ctx context.Context, m *DocServerGetProjectMutation) (Value, error) {
	switch m.Op() {
	case OpCreate:
		return (&DocServerGetProjectCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdate:
		return (&DocServerGetProjectUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdateOne:
		return (&DocServerGetProjectUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpDelete, OpDeleteOne:
		return (&DocServerGetProjectDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
	default:
		return nil, fmt.Errorf("serversitemicros: unknown DocServerGetProject mutation op: %q", m.Op())
	}
}

// DocServerProjectClient is a client for the DocServerProject schema.
type DocServerProjectClient struct {
	config
}

// NewDocServerProjectClient returns a client for the DocServerProject from the given config.
func NewDocServerProjectClient(c config) *DocServerProjectClient {
	return &DocServerProjectClient{config: c}
}

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

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

// Create returns a builder for creating a DocServerProject entity.
func (c *DocServerProjectClient) Create() *DocServerProjectCreate {
	mutation := newDocServerProjectMutation(c.config, OpCreate)
	return &DocServerProjectCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// CreateBulk returns a builder for creating a bulk of DocServerProject entities.
func (c *DocServerProjectClient) CreateBulk(builders ...*DocServerProjectCreate) *DocServerProjectCreateBulk {
	return &DocServerProjectCreateBulk{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 *DocServerProjectClient) MapCreateBulk(slice any, setFunc func(*DocServerProjectCreate, int)) *DocServerProjectCreateBulk {
	rv := reflect.ValueOf(slice)
	if rv.Kind() != reflect.Slice {
		return &DocServerProjectCreateBulk{err: fmt.Errorf("calling to DocServerProjectClient.MapCreateBulk with wrong type %T, need slice", slice)}
	}
	builders := make([]*DocServerProjectCreate, rv.Len())
	for i := 0; i < rv.Len(); i++ {
		builders[i] = c.Create()
		setFunc(builders[i], i)
	}
	return &DocServerProjectCreateBulk{config: c.config, builders: builders}
}

// Update returns an update builder for DocServerProject.
func (c *DocServerProjectClient) Update() *DocServerProjectUpdate {
	mutation := newDocServerProjectMutation(c.config, OpUpdate)
	return &DocServerProjectUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOne returns an update builder for the given entity.
func (c *DocServerProjectClient) UpdateOne(dsp *DocServerProject) *DocServerProjectUpdateOne {
	mutation := newDocServerProjectMutation(c.config, OpUpdateOne, withDocServerProject(dsp))
	return &DocServerProjectUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// UpdateOneID returns an update builder for the given id.
func (c *DocServerProjectClient) UpdateOneID(id int32) *DocServerProjectUpdateOne {
	mutation := newDocServerProjectMutation(c.config, OpUpdateOne, withDocServerProjectID(id))
	return &DocServerProjectUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// Delete returns a delete builder for DocServerProject.
func (c *DocServerProjectClient) Delete() *DocServerProjectDelete {
	mutation := newDocServerProjectMutation(c.config, OpDelete)
	return &DocServerProjectDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}

// DeleteOne returns a builder for deleting the given entity.
func (c *DocServerProjectClient) DeleteOne(dsp *DocServerProject) *DocServerProjectDeleteOne {
	return c.DeleteOneID(dsp.ID)
}

// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *DocServerProjectClient) DeleteOneID(id int32) *DocServerProjectDeleteOne {
	builder := c.Delete().Where(docserverproject.ID(id))
	builder.mutation.id = &id
	builder.mutation.op = OpDeleteOne
	return &DocServerProjectDeleteOne{builder}
}

// Query returns a query builder for DocServerProject.
func (c *DocServerProjectClient) Query() *DocServerProjectQuery {
	return &DocServerProjectQuery{
		config: c.config,
		ctx:    &QueryContext{Type: TypeDocServerProject},
		inters: c.Interceptors(),
	}
}

// Get returns a DocServerProject entity by its id.
func (c *DocServerProjectClient) Get(ctx context.Context, id int32) (*DocServerProject, error) {
	return c.Query().Where(docserverproject.ID(id)).Only(ctx)
}

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

// Hooks returns the client hooks.
func (c *DocServerProjectClient) Hooks() []Hook {
	hooks := c.hooks.DocServerProject
	return append(hooks[:len(hooks):len(hooks)], docserverproject.Hooks[:]...)
}

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

func (c *DocServerProjectClient) mutate(ctx context.Context, m *DocServerProjectMutation) (Value, error) {
	switch m.Op() {
	case OpCreate:
		return (&DocServerProjectCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdate:
		return (&DocServerProjectUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpUpdateOne:
		return (&DocServerProjectUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
	case OpDelete, OpDeleteOne:
		return (&DocServerProjectDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
	default:
		return nil, fmt.Errorf("serversitemicros: unknown DocServerProject mutation op: %q", m.Op())
	}
}

// hooks and interceptors per client, for fast access.
type (
	hooks struct {
		DocServerApp, DocServerCallback, DocServerGetProject,
		DocServerProject []ent.Hook
	}
	inters struct {
		DocServerApp, DocServerCallback, DocServerGetProject,
		DocServerProject []ent.Interceptor
	}
)
