github.com/ngocphuongnb/tetua@v0.0.7-alpha/packages/entrepository/ent/mutation.go (about)

     1  // Code generated by entc, DO NOT EDIT.
     2  
     3  package ent
     4  
     5  import (
     6  	"context"
     7  	"errors"
     8  	"fmt"
     9  	"sync"
    10  	"time"
    11  
    12  	"github.com/ngocphuongnb/tetua/packages/entrepository/ent/comment"
    13  	"github.com/ngocphuongnb/tetua/packages/entrepository/ent/file"
    14  	"github.com/ngocphuongnb/tetua/packages/entrepository/ent/page"
    15  	"github.com/ngocphuongnb/tetua/packages/entrepository/ent/permission"
    16  	"github.com/ngocphuongnb/tetua/packages/entrepository/ent/post"
    17  	"github.com/ngocphuongnb/tetua/packages/entrepository/ent/predicate"
    18  	"github.com/ngocphuongnb/tetua/packages/entrepository/ent/role"
    19  	"github.com/ngocphuongnb/tetua/packages/entrepository/ent/setting"
    20  	"github.com/ngocphuongnb/tetua/packages/entrepository/ent/topic"
    21  	"github.com/ngocphuongnb/tetua/packages/entrepository/ent/user"
    22  
    23  	"entgo.io/ent"
    24  )
    25  
    26  const (
    27  	// Operation types.
    28  	OpCreate    = ent.OpCreate
    29  	OpDelete    = ent.OpDelete
    30  	OpDeleteOne = ent.OpDeleteOne
    31  	OpUpdate    = ent.OpUpdate
    32  	OpUpdateOne = ent.OpUpdateOne
    33  
    34  	// Node types.
    35  	TypeComment    = "Comment"
    36  	TypeFile       = "File"
    37  	TypePage       = "Page"
    38  	TypePermission = "Permission"
    39  	TypePost       = "Post"
    40  	TypeRole       = "Role"
    41  	TypeSetting    = "Setting"
    42  	TypeTopic      = "Topic"
    43  	TypeUser       = "User"
    44  )
    45  
    46  // CommentMutation represents an operation that mutates the Comment nodes in the graph.
    47  type CommentMutation struct {
    48  	config
    49  	op              Op
    50  	typ             string
    51  	id              *int
    52  	created_at      *time.Time
    53  	updated_at      *time.Time
    54  	deleted_at      *time.Time
    55  	content         *string
    56  	content_html    *string
    57  	votes           *int64
    58  	addvotes        *int64
    59  	clearedFields   map[string]struct{}
    60  	post            *int
    61  	clearedpost     bool
    62  	user            *int
    63  	cleareduser     bool
    64  	children        map[int]struct{}
    65  	removedchildren map[int]struct{}
    66  	clearedchildren bool
    67  	parent          *int
    68  	clearedparent   bool
    69  	done            bool
    70  	oldValue        func(context.Context) (*Comment, error)
    71  	predicates      []predicate.Comment
    72  }
    73  
    74  var _ ent.Mutation = (*CommentMutation)(nil)
    75  
    76  // commentOption allows management of the mutation configuration using functional options.
    77  type commentOption func(*CommentMutation)
    78  
    79  // newCommentMutation creates new mutation for the Comment entity.
    80  func newCommentMutation(c config, op Op, opts ...commentOption) *CommentMutation {
    81  	m := &CommentMutation{
    82  		config:        c,
    83  		op:            op,
    84  		typ:           TypeComment,
    85  		clearedFields: make(map[string]struct{}),
    86  	}
    87  	for _, opt := range opts {
    88  		opt(m)
    89  	}
    90  	return m
    91  }
    92  
    93  // withCommentID sets the ID field of the mutation.
    94  func withCommentID(id int) commentOption {
    95  	return func(m *CommentMutation) {
    96  		var (
    97  			err   error
    98  			once  sync.Once
    99  			value *Comment
   100  		)
   101  		m.oldValue = func(ctx context.Context) (*Comment, error) {
   102  			once.Do(func() {
   103  				if m.done {
   104  					err = errors.New("querying old values post mutation is not allowed")
   105  				} else {
   106  					value, err = m.Client().Comment.Get(ctx, id)
   107  				}
   108  			})
   109  			return value, err
   110  		}
   111  		m.id = &id
   112  	}
   113  }
   114  
   115  // withComment sets the old Comment of the mutation.
   116  func withComment(node *Comment) commentOption {
   117  	return func(m *CommentMutation) {
   118  		m.oldValue = func(context.Context) (*Comment, error) {
   119  			return node, nil
   120  		}
   121  		m.id = &node.ID
   122  	}
   123  }
   124  
   125  // Client returns a new `ent.Client` from the mutation. If the mutation was
   126  // executed in a transaction (ent.Tx), a transactional client is returned.
   127  func (m CommentMutation) Client() *Client {
   128  	client := &Client{config: m.config}
   129  	client.init()
   130  	return client
   131  }
   132  
   133  // Tx returns an `ent.Tx` for mutations that were executed in transactions;
   134  // it returns an error otherwise.
   135  func (m CommentMutation) Tx() (*Tx, error) {
   136  	if _, ok := m.driver.(*txDriver); !ok {
   137  		return nil, errors.New("ent: mutation is not running in a transaction")
   138  	}
   139  	tx := &Tx{config: m.config}
   140  	tx.init()
   141  	return tx, nil
   142  }
   143  
   144  // ID returns the ID value in the mutation. Note that the ID is only available
   145  // if it was provided to the builder or after it was returned from the database.
   146  func (m *CommentMutation) ID() (id int, exists bool) {
   147  	if m.id == nil {
   148  		return
   149  	}
   150  	return *m.id, true
   151  }
   152  
   153  // IDs queries the database and returns the entity ids that match the mutation's predicate.
   154  // That means, if the mutation is applied within a transaction with an isolation level such
   155  // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
   156  // or updated by the mutation.
   157  func (m *CommentMutation) IDs(ctx context.Context) ([]int, error) {
   158  	switch {
   159  	case m.op.Is(OpUpdateOne | OpDeleteOne):
   160  		id, exists := m.ID()
   161  		if exists {
   162  			return []int{id}, nil
   163  		}
   164  		fallthrough
   165  	case m.op.Is(OpUpdate | OpDelete):
   166  		return m.Client().Comment.Query().Where(m.predicates...).IDs(ctx)
   167  	default:
   168  		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
   169  	}
   170  }
   171  
   172  // SetCreatedAt sets the "created_at" field.
   173  func (m *CommentMutation) SetCreatedAt(t time.Time) {
   174  	m.created_at = &t
   175  }
   176  
   177  // CreatedAt returns the value of the "created_at" field in the mutation.
   178  func (m *CommentMutation) CreatedAt() (r time.Time, exists bool) {
   179  	v := m.created_at
   180  	if v == nil {
   181  		return
   182  	}
   183  	return *v, true
   184  }
   185  
   186  // OldCreatedAt returns the old "created_at" field's value of the Comment entity.
   187  // If the Comment object wasn't provided to the builder, the object is fetched from the database.
   188  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
   189  func (m *CommentMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
   190  	if !m.op.Is(OpUpdateOne) {
   191  		return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
   192  	}
   193  	if m.id == nil || m.oldValue == nil {
   194  		return v, errors.New("OldCreatedAt requires an ID field in the mutation")
   195  	}
   196  	oldValue, err := m.oldValue(ctx)
   197  	if err != nil {
   198  		return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
   199  	}
   200  	return oldValue.CreatedAt, nil
   201  }
   202  
   203  // ResetCreatedAt resets all changes to the "created_at" field.
   204  func (m *CommentMutation) ResetCreatedAt() {
   205  	m.created_at = nil
   206  }
   207  
   208  // SetUpdatedAt sets the "updated_at" field.
   209  func (m *CommentMutation) SetUpdatedAt(t time.Time) {
   210  	m.updated_at = &t
   211  }
   212  
   213  // UpdatedAt returns the value of the "updated_at" field in the mutation.
   214  func (m *CommentMutation) UpdatedAt() (r time.Time, exists bool) {
   215  	v := m.updated_at
   216  	if v == nil {
   217  		return
   218  	}
   219  	return *v, true
   220  }
   221  
   222  // OldUpdatedAt returns the old "updated_at" field's value of the Comment entity.
   223  // If the Comment object wasn't provided to the builder, the object is fetched from the database.
   224  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
   225  func (m *CommentMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
   226  	if !m.op.Is(OpUpdateOne) {
   227  		return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
   228  	}
   229  	if m.id == nil || m.oldValue == nil {
   230  		return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
   231  	}
   232  	oldValue, err := m.oldValue(ctx)
   233  	if err != nil {
   234  		return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
   235  	}
   236  	return oldValue.UpdatedAt, nil
   237  }
   238  
   239  // ResetUpdatedAt resets all changes to the "updated_at" field.
   240  func (m *CommentMutation) ResetUpdatedAt() {
   241  	m.updated_at = nil
   242  }
   243  
   244  // SetDeletedAt sets the "deleted_at" field.
   245  func (m *CommentMutation) SetDeletedAt(t time.Time) {
   246  	m.deleted_at = &t
   247  }
   248  
   249  // DeletedAt returns the value of the "deleted_at" field in the mutation.
   250  func (m *CommentMutation) DeletedAt() (r time.Time, exists bool) {
   251  	v := m.deleted_at
   252  	if v == nil {
   253  		return
   254  	}
   255  	return *v, true
   256  }
   257  
   258  // OldDeletedAt returns the old "deleted_at" field's value of the Comment entity.
   259  // If the Comment object wasn't provided to the builder, the object is fetched from the database.
   260  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
   261  func (m *CommentMutation) OldDeletedAt(ctx context.Context) (v time.Time, err error) {
   262  	if !m.op.Is(OpUpdateOne) {
   263  		return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
   264  	}
   265  	if m.id == nil || m.oldValue == nil {
   266  		return v, errors.New("OldDeletedAt requires an ID field in the mutation")
   267  	}
   268  	oldValue, err := m.oldValue(ctx)
   269  	if err != nil {
   270  		return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
   271  	}
   272  	return oldValue.DeletedAt, nil
   273  }
   274  
   275  // ClearDeletedAt clears the value of the "deleted_at" field.
   276  func (m *CommentMutation) ClearDeletedAt() {
   277  	m.deleted_at = nil
   278  	m.clearedFields[comment.FieldDeletedAt] = struct{}{}
   279  }
   280  
   281  // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
   282  func (m *CommentMutation) DeletedAtCleared() bool {
   283  	_, ok := m.clearedFields[comment.FieldDeletedAt]
   284  	return ok
   285  }
   286  
   287  // ResetDeletedAt resets all changes to the "deleted_at" field.
   288  func (m *CommentMutation) ResetDeletedAt() {
   289  	m.deleted_at = nil
   290  	delete(m.clearedFields, comment.FieldDeletedAt)
   291  }
   292  
   293  // SetContent sets the "content" field.
   294  func (m *CommentMutation) SetContent(s string) {
   295  	m.content = &s
   296  }
   297  
   298  // Content returns the value of the "content" field in the mutation.
   299  func (m *CommentMutation) Content() (r string, exists bool) {
   300  	v := m.content
   301  	if v == nil {
   302  		return
   303  	}
   304  	return *v, true
   305  }
   306  
   307  // OldContent returns the old "content" field's value of the Comment entity.
   308  // If the Comment object wasn't provided to the builder, the object is fetched from the database.
   309  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
   310  func (m *CommentMutation) OldContent(ctx context.Context) (v string, err error) {
   311  	if !m.op.Is(OpUpdateOne) {
   312  		return v, errors.New("OldContent is only allowed on UpdateOne operations")
   313  	}
   314  	if m.id == nil || m.oldValue == nil {
   315  		return v, errors.New("OldContent requires an ID field in the mutation")
   316  	}
   317  	oldValue, err := m.oldValue(ctx)
   318  	if err != nil {
   319  		return v, fmt.Errorf("querying old value for OldContent: %w", err)
   320  	}
   321  	return oldValue.Content, nil
   322  }
   323  
   324  // ResetContent resets all changes to the "content" field.
   325  func (m *CommentMutation) ResetContent() {
   326  	m.content = nil
   327  }
   328  
   329  // SetContentHTML sets the "content_html" field.
   330  func (m *CommentMutation) SetContentHTML(s string) {
   331  	m.content_html = &s
   332  }
   333  
   334  // ContentHTML returns the value of the "content_html" field in the mutation.
   335  func (m *CommentMutation) ContentHTML() (r string, exists bool) {
   336  	v := m.content_html
   337  	if v == nil {
   338  		return
   339  	}
   340  	return *v, true
   341  }
   342  
   343  // OldContentHTML returns the old "content_html" field's value of the Comment entity.
   344  // If the Comment object wasn't provided to the builder, the object is fetched from the database.
   345  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
   346  func (m *CommentMutation) OldContentHTML(ctx context.Context) (v string, err error) {
   347  	if !m.op.Is(OpUpdateOne) {
   348  		return v, errors.New("OldContentHTML is only allowed on UpdateOne operations")
   349  	}
   350  	if m.id == nil || m.oldValue == nil {
   351  		return v, errors.New("OldContentHTML requires an ID field in the mutation")
   352  	}
   353  	oldValue, err := m.oldValue(ctx)
   354  	if err != nil {
   355  		return v, fmt.Errorf("querying old value for OldContentHTML: %w", err)
   356  	}
   357  	return oldValue.ContentHTML, nil
   358  }
   359  
   360  // ResetContentHTML resets all changes to the "content_html" field.
   361  func (m *CommentMutation) ResetContentHTML() {
   362  	m.content_html = nil
   363  }
   364  
   365  // SetVotes sets the "votes" field.
   366  func (m *CommentMutation) SetVotes(i int64) {
   367  	m.votes = &i
   368  	m.addvotes = nil
   369  }
   370  
   371  // Votes returns the value of the "votes" field in the mutation.
   372  func (m *CommentMutation) Votes() (r int64, exists bool) {
   373  	v := m.votes
   374  	if v == nil {
   375  		return
   376  	}
   377  	return *v, true
   378  }
   379  
   380  // OldVotes returns the old "votes" field's value of the Comment entity.
   381  // If the Comment object wasn't provided to the builder, the object is fetched from the database.
   382  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
   383  func (m *CommentMutation) OldVotes(ctx context.Context) (v int64, err error) {
   384  	if !m.op.Is(OpUpdateOne) {
   385  		return v, errors.New("OldVotes is only allowed on UpdateOne operations")
   386  	}
   387  	if m.id == nil || m.oldValue == nil {
   388  		return v, errors.New("OldVotes requires an ID field in the mutation")
   389  	}
   390  	oldValue, err := m.oldValue(ctx)
   391  	if err != nil {
   392  		return v, fmt.Errorf("querying old value for OldVotes: %w", err)
   393  	}
   394  	return oldValue.Votes, nil
   395  }
   396  
   397  // AddVotes adds i to the "votes" field.
   398  func (m *CommentMutation) AddVotes(i int64) {
   399  	if m.addvotes != nil {
   400  		*m.addvotes += i
   401  	} else {
   402  		m.addvotes = &i
   403  	}
   404  }
   405  
   406  // AddedVotes returns the value that was added to the "votes" field in this mutation.
   407  func (m *CommentMutation) AddedVotes() (r int64, exists bool) {
   408  	v := m.addvotes
   409  	if v == nil {
   410  		return
   411  	}
   412  	return *v, true
   413  }
   414  
   415  // ResetVotes resets all changes to the "votes" field.
   416  func (m *CommentMutation) ResetVotes() {
   417  	m.votes = nil
   418  	m.addvotes = nil
   419  }
   420  
   421  // SetPostID sets the "post_id" field.
   422  func (m *CommentMutation) SetPostID(i int) {
   423  	m.post = &i
   424  }
   425  
   426  // PostID returns the value of the "post_id" field in the mutation.
   427  func (m *CommentMutation) PostID() (r int, exists bool) {
   428  	v := m.post
   429  	if v == nil {
   430  		return
   431  	}
   432  	return *v, true
   433  }
   434  
   435  // OldPostID returns the old "post_id" field's value of the Comment entity.
   436  // If the Comment object wasn't provided to the builder, the object is fetched from the database.
   437  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
   438  func (m *CommentMutation) OldPostID(ctx context.Context) (v int, err error) {
   439  	if !m.op.Is(OpUpdateOne) {
   440  		return v, errors.New("OldPostID is only allowed on UpdateOne operations")
   441  	}
   442  	if m.id == nil || m.oldValue == nil {
   443  		return v, errors.New("OldPostID requires an ID field in the mutation")
   444  	}
   445  	oldValue, err := m.oldValue(ctx)
   446  	if err != nil {
   447  		return v, fmt.Errorf("querying old value for OldPostID: %w", err)
   448  	}
   449  	return oldValue.PostID, nil
   450  }
   451  
   452  // ClearPostID clears the value of the "post_id" field.
   453  func (m *CommentMutation) ClearPostID() {
   454  	m.post = nil
   455  	m.clearedFields[comment.FieldPostID] = struct{}{}
   456  }
   457  
   458  // PostIDCleared returns if the "post_id" field was cleared in this mutation.
   459  func (m *CommentMutation) PostIDCleared() bool {
   460  	_, ok := m.clearedFields[comment.FieldPostID]
   461  	return ok
   462  }
   463  
   464  // ResetPostID resets all changes to the "post_id" field.
   465  func (m *CommentMutation) ResetPostID() {
   466  	m.post = nil
   467  	delete(m.clearedFields, comment.FieldPostID)
   468  }
   469  
   470  // SetUserID sets the "user_id" field.
   471  func (m *CommentMutation) SetUserID(i int) {
   472  	m.user = &i
   473  }
   474  
   475  // UserID returns the value of the "user_id" field in the mutation.
   476  func (m *CommentMutation) UserID() (r int, exists bool) {
   477  	v := m.user
   478  	if v == nil {
   479  		return
   480  	}
   481  	return *v, true
   482  }
   483  
   484  // OldUserID returns the old "user_id" field's value of the Comment entity.
   485  // If the Comment object wasn't provided to the builder, the object is fetched from the database.
   486  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
   487  func (m *CommentMutation) OldUserID(ctx context.Context) (v int, err error) {
   488  	if !m.op.Is(OpUpdateOne) {
   489  		return v, errors.New("OldUserID is only allowed on UpdateOne operations")
   490  	}
   491  	if m.id == nil || m.oldValue == nil {
   492  		return v, errors.New("OldUserID requires an ID field in the mutation")
   493  	}
   494  	oldValue, err := m.oldValue(ctx)
   495  	if err != nil {
   496  		return v, fmt.Errorf("querying old value for OldUserID: %w", err)
   497  	}
   498  	return oldValue.UserID, nil
   499  }
   500  
   501  // ClearUserID clears the value of the "user_id" field.
   502  func (m *CommentMutation) ClearUserID() {
   503  	m.user = nil
   504  	m.clearedFields[comment.FieldUserID] = struct{}{}
   505  }
   506  
   507  // UserIDCleared returns if the "user_id" field was cleared in this mutation.
   508  func (m *CommentMutation) UserIDCleared() bool {
   509  	_, ok := m.clearedFields[comment.FieldUserID]
   510  	return ok
   511  }
   512  
   513  // ResetUserID resets all changes to the "user_id" field.
   514  func (m *CommentMutation) ResetUserID() {
   515  	m.user = nil
   516  	delete(m.clearedFields, comment.FieldUserID)
   517  }
   518  
   519  // SetParentID sets the "parent_id" field.
   520  func (m *CommentMutation) SetParentID(i int) {
   521  	m.parent = &i
   522  }
   523  
   524  // ParentID returns the value of the "parent_id" field in the mutation.
   525  func (m *CommentMutation) ParentID() (r int, exists bool) {
   526  	v := m.parent
   527  	if v == nil {
   528  		return
   529  	}
   530  	return *v, true
   531  }
   532  
   533  // OldParentID returns the old "parent_id" field's value of the Comment entity.
   534  // If the Comment object wasn't provided to the builder, the object is fetched from the database.
   535  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
   536  func (m *CommentMutation) OldParentID(ctx context.Context) (v int, err error) {
   537  	if !m.op.Is(OpUpdateOne) {
   538  		return v, errors.New("OldParentID is only allowed on UpdateOne operations")
   539  	}
   540  	if m.id == nil || m.oldValue == nil {
   541  		return v, errors.New("OldParentID requires an ID field in the mutation")
   542  	}
   543  	oldValue, err := m.oldValue(ctx)
   544  	if err != nil {
   545  		return v, fmt.Errorf("querying old value for OldParentID: %w", err)
   546  	}
   547  	return oldValue.ParentID, nil
   548  }
   549  
   550  // ClearParentID clears the value of the "parent_id" field.
   551  func (m *CommentMutation) ClearParentID() {
   552  	m.parent = nil
   553  	m.clearedFields[comment.FieldParentID] = struct{}{}
   554  }
   555  
   556  // ParentIDCleared returns if the "parent_id" field was cleared in this mutation.
   557  func (m *CommentMutation) ParentIDCleared() bool {
   558  	_, ok := m.clearedFields[comment.FieldParentID]
   559  	return ok
   560  }
   561  
   562  // ResetParentID resets all changes to the "parent_id" field.
   563  func (m *CommentMutation) ResetParentID() {
   564  	m.parent = nil
   565  	delete(m.clearedFields, comment.FieldParentID)
   566  }
   567  
   568  // ClearPost clears the "post" edge to the Post entity.
   569  func (m *CommentMutation) ClearPost() {
   570  	m.clearedpost = true
   571  }
   572  
   573  // PostCleared reports if the "post" edge to the Post entity was cleared.
   574  func (m *CommentMutation) PostCleared() bool {
   575  	return m.PostIDCleared() || m.clearedpost
   576  }
   577  
   578  // PostIDs returns the "post" edge IDs in the mutation.
   579  // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
   580  // PostID instead. It exists only for internal usage by the builders.
   581  func (m *CommentMutation) PostIDs() (ids []int) {
   582  	if id := m.post; id != nil {
   583  		ids = append(ids, *id)
   584  	}
   585  	return
   586  }
   587  
   588  // ResetPost resets all changes to the "post" edge.
   589  func (m *CommentMutation) ResetPost() {
   590  	m.post = nil
   591  	m.clearedpost = false
   592  }
   593  
   594  // ClearUser clears the "user" edge to the User entity.
   595  func (m *CommentMutation) ClearUser() {
   596  	m.cleareduser = true
   597  }
   598  
   599  // UserCleared reports if the "user" edge to the User entity was cleared.
   600  func (m *CommentMutation) UserCleared() bool {
   601  	return m.UserIDCleared() || m.cleareduser
   602  }
   603  
   604  // UserIDs returns the "user" edge IDs in the mutation.
   605  // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
   606  // UserID instead. It exists only for internal usage by the builders.
   607  func (m *CommentMutation) UserIDs() (ids []int) {
   608  	if id := m.user; id != nil {
   609  		ids = append(ids, *id)
   610  	}
   611  	return
   612  }
   613  
   614  // ResetUser resets all changes to the "user" edge.
   615  func (m *CommentMutation) ResetUser() {
   616  	m.user = nil
   617  	m.cleareduser = false
   618  }
   619  
   620  // AddChildIDs adds the "children" edge to the Comment entity by ids.
   621  func (m *CommentMutation) AddChildIDs(ids ...int) {
   622  	if m.children == nil {
   623  		m.children = make(map[int]struct{})
   624  	}
   625  	for i := range ids {
   626  		m.children[ids[i]] = struct{}{}
   627  	}
   628  }
   629  
   630  // ClearChildren clears the "children" edge to the Comment entity.
   631  func (m *CommentMutation) ClearChildren() {
   632  	m.clearedchildren = true
   633  }
   634  
   635  // ChildrenCleared reports if the "children" edge to the Comment entity was cleared.
   636  func (m *CommentMutation) ChildrenCleared() bool {
   637  	return m.clearedchildren
   638  }
   639  
   640  // RemoveChildIDs removes the "children" edge to the Comment entity by IDs.
   641  func (m *CommentMutation) RemoveChildIDs(ids ...int) {
   642  	if m.removedchildren == nil {
   643  		m.removedchildren = make(map[int]struct{})
   644  	}
   645  	for i := range ids {
   646  		delete(m.children, ids[i])
   647  		m.removedchildren[ids[i]] = struct{}{}
   648  	}
   649  }
   650  
   651  // RemovedChildren returns the removed IDs of the "children" edge to the Comment entity.
   652  func (m *CommentMutation) RemovedChildrenIDs() (ids []int) {
   653  	for id := range m.removedchildren {
   654  		ids = append(ids, id)
   655  	}
   656  	return
   657  }
   658  
   659  // ChildrenIDs returns the "children" edge IDs in the mutation.
   660  func (m *CommentMutation) ChildrenIDs() (ids []int) {
   661  	for id := range m.children {
   662  		ids = append(ids, id)
   663  	}
   664  	return
   665  }
   666  
   667  // ResetChildren resets all changes to the "children" edge.
   668  func (m *CommentMutation) ResetChildren() {
   669  	m.children = nil
   670  	m.clearedchildren = false
   671  	m.removedchildren = nil
   672  }
   673  
   674  // ClearParent clears the "parent" edge to the Comment entity.
   675  func (m *CommentMutation) ClearParent() {
   676  	m.clearedparent = true
   677  }
   678  
   679  // ParentCleared reports if the "parent" edge to the Comment entity was cleared.
   680  func (m *CommentMutation) ParentCleared() bool {
   681  	return m.ParentIDCleared() || m.clearedparent
   682  }
   683  
   684  // ParentIDs returns the "parent" edge IDs in the mutation.
   685  // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
   686  // ParentID instead. It exists only for internal usage by the builders.
   687  func (m *CommentMutation) ParentIDs() (ids []int) {
   688  	if id := m.parent; id != nil {
   689  		ids = append(ids, *id)
   690  	}
   691  	return
   692  }
   693  
   694  // ResetParent resets all changes to the "parent" edge.
   695  func (m *CommentMutation) ResetParent() {
   696  	m.parent = nil
   697  	m.clearedparent = false
   698  }
   699  
   700  // Where appends a list predicates to the CommentMutation builder.
   701  func (m *CommentMutation) Where(ps ...predicate.Comment) {
   702  	m.predicates = append(m.predicates, ps...)
   703  }
   704  
   705  // Op returns the operation name.
   706  func (m *CommentMutation) Op() Op {
   707  	return m.op
   708  }
   709  
   710  // Type returns the node type of this mutation (Comment).
   711  func (m *CommentMutation) Type() string {
   712  	return m.typ
   713  }
   714  
   715  // Fields returns all fields that were changed during this mutation. Note that in
   716  // order to get all numeric fields that were incremented/decremented, call
   717  // AddedFields().
   718  func (m *CommentMutation) Fields() []string {
   719  	fields := make([]string, 0, 9)
   720  	if m.created_at != nil {
   721  		fields = append(fields, comment.FieldCreatedAt)
   722  	}
   723  	if m.updated_at != nil {
   724  		fields = append(fields, comment.FieldUpdatedAt)
   725  	}
   726  	if m.deleted_at != nil {
   727  		fields = append(fields, comment.FieldDeletedAt)
   728  	}
   729  	if m.content != nil {
   730  		fields = append(fields, comment.FieldContent)
   731  	}
   732  	if m.content_html != nil {
   733  		fields = append(fields, comment.FieldContentHTML)
   734  	}
   735  	if m.votes != nil {
   736  		fields = append(fields, comment.FieldVotes)
   737  	}
   738  	if m.post != nil {
   739  		fields = append(fields, comment.FieldPostID)
   740  	}
   741  	if m.user != nil {
   742  		fields = append(fields, comment.FieldUserID)
   743  	}
   744  	if m.parent != nil {
   745  		fields = append(fields, comment.FieldParentID)
   746  	}
   747  	return fields
   748  }
   749  
   750  // Field returns the value of a field with the given name. The second boolean
   751  // return value indicates that this field was not set, or was not defined in the
   752  // schema.
   753  func (m *CommentMutation) Field(name string) (ent.Value, bool) {
   754  	switch name {
   755  	case comment.FieldCreatedAt:
   756  		return m.CreatedAt()
   757  	case comment.FieldUpdatedAt:
   758  		return m.UpdatedAt()
   759  	case comment.FieldDeletedAt:
   760  		return m.DeletedAt()
   761  	case comment.FieldContent:
   762  		return m.Content()
   763  	case comment.FieldContentHTML:
   764  		return m.ContentHTML()
   765  	case comment.FieldVotes:
   766  		return m.Votes()
   767  	case comment.FieldPostID:
   768  		return m.PostID()
   769  	case comment.FieldUserID:
   770  		return m.UserID()
   771  	case comment.FieldParentID:
   772  		return m.ParentID()
   773  	}
   774  	return nil, false
   775  }
   776  
   777  // OldField returns the old value of the field from the database. An error is
   778  // returned if the mutation operation is not UpdateOne, or the query to the
   779  // database failed.
   780  func (m *CommentMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
   781  	switch name {
   782  	case comment.FieldCreatedAt:
   783  		return m.OldCreatedAt(ctx)
   784  	case comment.FieldUpdatedAt:
   785  		return m.OldUpdatedAt(ctx)
   786  	case comment.FieldDeletedAt:
   787  		return m.OldDeletedAt(ctx)
   788  	case comment.FieldContent:
   789  		return m.OldContent(ctx)
   790  	case comment.FieldContentHTML:
   791  		return m.OldContentHTML(ctx)
   792  	case comment.FieldVotes:
   793  		return m.OldVotes(ctx)
   794  	case comment.FieldPostID:
   795  		return m.OldPostID(ctx)
   796  	case comment.FieldUserID:
   797  		return m.OldUserID(ctx)
   798  	case comment.FieldParentID:
   799  		return m.OldParentID(ctx)
   800  	}
   801  	return nil, fmt.Errorf("unknown Comment field %s", name)
   802  }
   803  
   804  // SetField sets the value of a field with the given name. It returns an error if
   805  // the field is not defined in the schema, or if the type mismatched the field
   806  // type.
   807  func (m *CommentMutation) SetField(name string, value ent.Value) error {
   808  	switch name {
   809  	case comment.FieldCreatedAt:
   810  		v, ok := value.(time.Time)
   811  		if !ok {
   812  			return fmt.Errorf("unexpected type %T for field %s", value, name)
   813  		}
   814  		m.SetCreatedAt(v)
   815  		return nil
   816  	case comment.FieldUpdatedAt:
   817  		v, ok := value.(time.Time)
   818  		if !ok {
   819  			return fmt.Errorf("unexpected type %T for field %s", value, name)
   820  		}
   821  		m.SetUpdatedAt(v)
   822  		return nil
   823  	case comment.FieldDeletedAt:
   824  		v, ok := value.(time.Time)
   825  		if !ok {
   826  			return fmt.Errorf("unexpected type %T for field %s", value, name)
   827  		}
   828  		m.SetDeletedAt(v)
   829  		return nil
   830  	case comment.FieldContent:
   831  		v, ok := value.(string)
   832  		if !ok {
   833  			return fmt.Errorf("unexpected type %T for field %s", value, name)
   834  		}
   835  		m.SetContent(v)
   836  		return nil
   837  	case comment.FieldContentHTML:
   838  		v, ok := value.(string)
   839  		if !ok {
   840  			return fmt.Errorf("unexpected type %T for field %s", value, name)
   841  		}
   842  		m.SetContentHTML(v)
   843  		return nil
   844  	case comment.FieldVotes:
   845  		v, ok := value.(int64)
   846  		if !ok {
   847  			return fmt.Errorf("unexpected type %T for field %s", value, name)
   848  		}
   849  		m.SetVotes(v)
   850  		return nil
   851  	case comment.FieldPostID:
   852  		v, ok := value.(int)
   853  		if !ok {
   854  			return fmt.Errorf("unexpected type %T for field %s", value, name)
   855  		}
   856  		m.SetPostID(v)
   857  		return nil
   858  	case comment.FieldUserID:
   859  		v, ok := value.(int)
   860  		if !ok {
   861  			return fmt.Errorf("unexpected type %T for field %s", value, name)
   862  		}
   863  		m.SetUserID(v)
   864  		return nil
   865  	case comment.FieldParentID:
   866  		v, ok := value.(int)
   867  		if !ok {
   868  			return fmt.Errorf("unexpected type %T for field %s", value, name)
   869  		}
   870  		m.SetParentID(v)
   871  		return nil
   872  	}
   873  	return fmt.Errorf("unknown Comment field %s", name)
   874  }
   875  
   876  // AddedFields returns all numeric fields that were incremented/decremented during
   877  // this mutation.
   878  func (m *CommentMutation) AddedFields() []string {
   879  	var fields []string
   880  	if m.addvotes != nil {
   881  		fields = append(fields, comment.FieldVotes)
   882  	}
   883  	return fields
   884  }
   885  
   886  // AddedField returns the numeric value that was incremented/decremented on a field
   887  // with the given name. The second boolean return value indicates that this field
   888  // was not set, or was not defined in the schema.
   889  func (m *CommentMutation) AddedField(name string) (ent.Value, bool) {
   890  	switch name {
   891  	case comment.FieldVotes:
   892  		return m.AddedVotes()
   893  	}
   894  	return nil, false
   895  }
   896  
   897  // AddField adds the value to the field with the given name. It returns an error if
   898  // the field is not defined in the schema, or if the type mismatched the field
   899  // type.
   900  func (m *CommentMutation) AddField(name string, value ent.Value) error {
   901  	switch name {
   902  	case comment.FieldVotes:
   903  		v, ok := value.(int64)
   904  		if !ok {
   905  			return fmt.Errorf("unexpected type %T for field %s", value, name)
   906  		}
   907  		m.AddVotes(v)
   908  		return nil
   909  	}
   910  	return fmt.Errorf("unknown Comment numeric field %s", name)
   911  }
   912  
   913  // ClearedFields returns all nullable fields that were cleared during this
   914  // mutation.
   915  func (m *CommentMutation) ClearedFields() []string {
   916  	var fields []string
   917  	if m.FieldCleared(comment.FieldDeletedAt) {
   918  		fields = append(fields, comment.FieldDeletedAt)
   919  	}
   920  	if m.FieldCleared(comment.FieldPostID) {
   921  		fields = append(fields, comment.FieldPostID)
   922  	}
   923  	if m.FieldCleared(comment.FieldUserID) {
   924  		fields = append(fields, comment.FieldUserID)
   925  	}
   926  	if m.FieldCleared(comment.FieldParentID) {
   927  		fields = append(fields, comment.FieldParentID)
   928  	}
   929  	return fields
   930  }
   931  
   932  // FieldCleared returns a boolean indicating if a field with the given name was
   933  // cleared in this mutation.
   934  func (m *CommentMutation) FieldCleared(name string) bool {
   935  	_, ok := m.clearedFields[name]
   936  	return ok
   937  }
   938  
   939  // ClearField clears the value of the field with the given name. It returns an
   940  // error if the field is not defined in the schema.
   941  func (m *CommentMutation) ClearField(name string) error {
   942  	switch name {
   943  	case comment.FieldDeletedAt:
   944  		m.ClearDeletedAt()
   945  		return nil
   946  	case comment.FieldPostID:
   947  		m.ClearPostID()
   948  		return nil
   949  	case comment.FieldUserID:
   950  		m.ClearUserID()
   951  		return nil
   952  	case comment.FieldParentID:
   953  		m.ClearParentID()
   954  		return nil
   955  	}
   956  	return fmt.Errorf("unknown Comment nullable field %s", name)
   957  }
   958  
   959  // ResetField resets all changes in the mutation for the field with the given name.
   960  // It returns an error if the field is not defined in the schema.
   961  func (m *CommentMutation) ResetField(name string) error {
   962  	switch name {
   963  	case comment.FieldCreatedAt:
   964  		m.ResetCreatedAt()
   965  		return nil
   966  	case comment.FieldUpdatedAt:
   967  		m.ResetUpdatedAt()
   968  		return nil
   969  	case comment.FieldDeletedAt:
   970  		m.ResetDeletedAt()
   971  		return nil
   972  	case comment.FieldContent:
   973  		m.ResetContent()
   974  		return nil
   975  	case comment.FieldContentHTML:
   976  		m.ResetContentHTML()
   977  		return nil
   978  	case comment.FieldVotes:
   979  		m.ResetVotes()
   980  		return nil
   981  	case comment.FieldPostID:
   982  		m.ResetPostID()
   983  		return nil
   984  	case comment.FieldUserID:
   985  		m.ResetUserID()
   986  		return nil
   987  	case comment.FieldParentID:
   988  		m.ResetParentID()
   989  		return nil
   990  	}
   991  	return fmt.Errorf("unknown Comment field %s", name)
   992  }
   993  
   994  // AddedEdges returns all edge names that were set/added in this mutation.
   995  func (m *CommentMutation) AddedEdges() []string {
   996  	edges := make([]string, 0, 4)
   997  	if m.post != nil {
   998  		edges = append(edges, comment.EdgePost)
   999  	}
  1000  	if m.user != nil {
  1001  		edges = append(edges, comment.EdgeUser)
  1002  	}
  1003  	if m.children != nil {
  1004  		edges = append(edges, comment.EdgeChildren)
  1005  	}
  1006  	if m.parent != nil {
  1007  		edges = append(edges, comment.EdgeParent)
  1008  	}
  1009  	return edges
  1010  }
  1011  
  1012  // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  1013  // name in this mutation.
  1014  func (m *CommentMutation) AddedIDs(name string) []ent.Value {
  1015  	switch name {
  1016  	case comment.EdgePost:
  1017  		if id := m.post; id != nil {
  1018  			return []ent.Value{*id}
  1019  		}
  1020  	case comment.EdgeUser:
  1021  		if id := m.user; id != nil {
  1022  			return []ent.Value{*id}
  1023  		}
  1024  	case comment.EdgeChildren:
  1025  		ids := make([]ent.Value, 0, len(m.children))
  1026  		for id := range m.children {
  1027  			ids = append(ids, id)
  1028  		}
  1029  		return ids
  1030  	case comment.EdgeParent:
  1031  		if id := m.parent; id != nil {
  1032  			return []ent.Value{*id}
  1033  		}
  1034  	}
  1035  	return nil
  1036  }
  1037  
  1038  // RemovedEdges returns all edge names that were removed in this mutation.
  1039  func (m *CommentMutation) RemovedEdges() []string {
  1040  	edges := make([]string, 0, 4)
  1041  	if m.removedchildren != nil {
  1042  		edges = append(edges, comment.EdgeChildren)
  1043  	}
  1044  	return edges
  1045  }
  1046  
  1047  // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  1048  // the given name in this mutation.
  1049  func (m *CommentMutation) RemovedIDs(name string) []ent.Value {
  1050  	switch name {
  1051  	case comment.EdgeChildren:
  1052  		ids := make([]ent.Value, 0, len(m.removedchildren))
  1053  		for id := range m.removedchildren {
  1054  			ids = append(ids, id)
  1055  		}
  1056  		return ids
  1057  	}
  1058  	return nil
  1059  }
  1060  
  1061  // ClearedEdges returns all edge names that were cleared in this mutation.
  1062  func (m *CommentMutation) ClearedEdges() []string {
  1063  	edges := make([]string, 0, 4)
  1064  	if m.clearedpost {
  1065  		edges = append(edges, comment.EdgePost)
  1066  	}
  1067  	if m.cleareduser {
  1068  		edges = append(edges, comment.EdgeUser)
  1069  	}
  1070  	if m.clearedchildren {
  1071  		edges = append(edges, comment.EdgeChildren)
  1072  	}
  1073  	if m.clearedparent {
  1074  		edges = append(edges, comment.EdgeParent)
  1075  	}
  1076  	return edges
  1077  }
  1078  
  1079  // EdgeCleared returns a boolean which indicates if the edge with the given name
  1080  // was cleared in this mutation.
  1081  func (m *CommentMutation) EdgeCleared(name string) bool {
  1082  	switch name {
  1083  	case comment.EdgePost:
  1084  		return m.clearedpost
  1085  	case comment.EdgeUser:
  1086  		return m.cleareduser
  1087  	case comment.EdgeChildren:
  1088  		return m.clearedchildren
  1089  	case comment.EdgeParent:
  1090  		return m.clearedparent
  1091  	}
  1092  	return false
  1093  }
  1094  
  1095  // ClearEdge clears the value of the edge with the given name. It returns an error
  1096  // if that edge is not defined in the schema.
  1097  func (m *CommentMutation) ClearEdge(name string) error {
  1098  	switch name {
  1099  	case comment.EdgePost:
  1100  		m.ClearPost()
  1101  		return nil
  1102  	case comment.EdgeUser:
  1103  		m.ClearUser()
  1104  		return nil
  1105  	case comment.EdgeParent:
  1106  		m.ClearParent()
  1107  		return nil
  1108  	}
  1109  	return fmt.Errorf("unknown Comment unique edge %s", name)
  1110  }
  1111  
  1112  // ResetEdge resets all changes to the edge with the given name in this mutation.
  1113  // It returns an error if the edge is not defined in the schema.
  1114  func (m *CommentMutation) ResetEdge(name string) error {
  1115  	switch name {
  1116  	case comment.EdgePost:
  1117  		m.ResetPost()
  1118  		return nil
  1119  	case comment.EdgeUser:
  1120  		m.ResetUser()
  1121  		return nil
  1122  	case comment.EdgeChildren:
  1123  		m.ResetChildren()
  1124  		return nil
  1125  	case comment.EdgeParent:
  1126  		m.ResetParent()
  1127  		return nil
  1128  	}
  1129  	return fmt.Errorf("unknown Comment edge %s", name)
  1130  }
  1131  
  1132  // FileMutation represents an operation that mutates the File nodes in the graph.
  1133  type FileMutation struct {
  1134  	config
  1135  	op                  Op
  1136  	typ                 string
  1137  	id                  *int
  1138  	created_at          *time.Time
  1139  	updated_at          *time.Time
  1140  	deleted_at          *time.Time
  1141  	disk                *string
  1142  	_path               *string
  1143  	_type               *string
  1144  	size                *int
  1145  	addsize             *int
  1146  	clearedFields       map[string]struct{}
  1147  	user                *int
  1148  	cleareduser         bool
  1149  	posts               map[int]struct{}
  1150  	removedposts        map[int]struct{}
  1151  	clearedposts        bool
  1152  	pages               map[int]struct{}
  1153  	removedpages        map[int]struct{}
  1154  	clearedpages        bool
  1155  	user_avatars        map[int]struct{}
  1156  	removeduser_avatars map[int]struct{}
  1157  	cleareduser_avatars bool
  1158  	done                bool
  1159  	oldValue            func(context.Context) (*File, error)
  1160  	predicates          []predicate.File
  1161  }
  1162  
  1163  var _ ent.Mutation = (*FileMutation)(nil)
  1164  
  1165  // fileOption allows management of the mutation configuration using functional options.
  1166  type fileOption func(*FileMutation)
  1167  
  1168  // newFileMutation creates new mutation for the File entity.
  1169  func newFileMutation(c config, op Op, opts ...fileOption) *FileMutation {
  1170  	m := &FileMutation{
  1171  		config:        c,
  1172  		op:            op,
  1173  		typ:           TypeFile,
  1174  		clearedFields: make(map[string]struct{}),
  1175  	}
  1176  	for _, opt := range opts {
  1177  		opt(m)
  1178  	}
  1179  	return m
  1180  }
  1181  
  1182  // withFileID sets the ID field of the mutation.
  1183  func withFileID(id int) fileOption {
  1184  	return func(m *FileMutation) {
  1185  		var (
  1186  			err   error
  1187  			once  sync.Once
  1188  			value *File
  1189  		)
  1190  		m.oldValue = func(ctx context.Context) (*File, error) {
  1191  			once.Do(func() {
  1192  				if m.done {
  1193  					err = errors.New("querying old values post mutation is not allowed")
  1194  				} else {
  1195  					value, err = m.Client().File.Get(ctx, id)
  1196  				}
  1197  			})
  1198  			return value, err
  1199  		}
  1200  		m.id = &id
  1201  	}
  1202  }
  1203  
  1204  // withFile sets the old File of the mutation.
  1205  func withFile(node *File) fileOption {
  1206  	return func(m *FileMutation) {
  1207  		m.oldValue = func(context.Context) (*File, error) {
  1208  			return node, nil
  1209  		}
  1210  		m.id = &node.ID
  1211  	}
  1212  }
  1213  
  1214  // Client returns a new `ent.Client` from the mutation. If the mutation was
  1215  // executed in a transaction (ent.Tx), a transactional client is returned.
  1216  func (m FileMutation) Client() *Client {
  1217  	client := &Client{config: m.config}
  1218  	client.init()
  1219  	return client
  1220  }
  1221  
  1222  // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  1223  // it returns an error otherwise.
  1224  func (m FileMutation) Tx() (*Tx, error) {
  1225  	if _, ok := m.driver.(*txDriver); !ok {
  1226  		return nil, errors.New("ent: mutation is not running in a transaction")
  1227  	}
  1228  	tx := &Tx{config: m.config}
  1229  	tx.init()
  1230  	return tx, nil
  1231  }
  1232  
  1233  // ID returns the ID value in the mutation. Note that the ID is only available
  1234  // if it was provided to the builder or after it was returned from the database.
  1235  func (m *FileMutation) ID() (id int, exists bool) {
  1236  	if m.id == nil {
  1237  		return
  1238  	}
  1239  	return *m.id, true
  1240  }
  1241  
  1242  // IDs queries the database and returns the entity ids that match the mutation's predicate.
  1243  // That means, if the mutation is applied within a transaction with an isolation level such
  1244  // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  1245  // or updated by the mutation.
  1246  func (m *FileMutation) IDs(ctx context.Context) ([]int, error) {
  1247  	switch {
  1248  	case m.op.Is(OpUpdateOne | OpDeleteOne):
  1249  		id, exists := m.ID()
  1250  		if exists {
  1251  			return []int{id}, nil
  1252  		}
  1253  		fallthrough
  1254  	case m.op.Is(OpUpdate | OpDelete):
  1255  		return m.Client().File.Query().Where(m.predicates...).IDs(ctx)
  1256  	default:
  1257  		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  1258  	}
  1259  }
  1260  
  1261  // SetCreatedAt sets the "created_at" field.
  1262  func (m *FileMutation) SetCreatedAt(t time.Time) {
  1263  	m.created_at = &t
  1264  }
  1265  
  1266  // CreatedAt returns the value of the "created_at" field in the mutation.
  1267  func (m *FileMutation) CreatedAt() (r time.Time, exists bool) {
  1268  	v := m.created_at
  1269  	if v == nil {
  1270  		return
  1271  	}
  1272  	return *v, true
  1273  }
  1274  
  1275  // OldCreatedAt returns the old "created_at" field's value of the File entity.
  1276  // If the File object wasn't provided to the builder, the object is fetched from the database.
  1277  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1278  func (m *FileMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  1279  	if !m.op.Is(OpUpdateOne) {
  1280  		return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  1281  	}
  1282  	if m.id == nil || m.oldValue == nil {
  1283  		return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  1284  	}
  1285  	oldValue, err := m.oldValue(ctx)
  1286  	if err != nil {
  1287  		return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  1288  	}
  1289  	return oldValue.CreatedAt, nil
  1290  }
  1291  
  1292  // ResetCreatedAt resets all changes to the "created_at" field.
  1293  func (m *FileMutation) ResetCreatedAt() {
  1294  	m.created_at = nil
  1295  }
  1296  
  1297  // SetUpdatedAt sets the "updated_at" field.
  1298  func (m *FileMutation) SetUpdatedAt(t time.Time) {
  1299  	m.updated_at = &t
  1300  }
  1301  
  1302  // UpdatedAt returns the value of the "updated_at" field in the mutation.
  1303  func (m *FileMutation) UpdatedAt() (r time.Time, exists bool) {
  1304  	v := m.updated_at
  1305  	if v == nil {
  1306  		return
  1307  	}
  1308  	return *v, true
  1309  }
  1310  
  1311  // OldUpdatedAt returns the old "updated_at" field's value of the File entity.
  1312  // If the File object wasn't provided to the builder, the object is fetched from the database.
  1313  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1314  func (m *FileMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  1315  	if !m.op.Is(OpUpdateOne) {
  1316  		return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  1317  	}
  1318  	if m.id == nil || m.oldValue == nil {
  1319  		return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  1320  	}
  1321  	oldValue, err := m.oldValue(ctx)
  1322  	if err != nil {
  1323  		return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  1324  	}
  1325  	return oldValue.UpdatedAt, nil
  1326  }
  1327  
  1328  // ResetUpdatedAt resets all changes to the "updated_at" field.
  1329  func (m *FileMutation) ResetUpdatedAt() {
  1330  	m.updated_at = nil
  1331  }
  1332  
  1333  // SetDeletedAt sets the "deleted_at" field.
  1334  func (m *FileMutation) SetDeletedAt(t time.Time) {
  1335  	m.deleted_at = &t
  1336  }
  1337  
  1338  // DeletedAt returns the value of the "deleted_at" field in the mutation.
  1339  func (m *FileMutation) DeletedAt() (r time.Time, exists bool) {
  1340  	v := m.deleted_at
  1341  	if v == nil {
  1342  		return
  1343  	}
  1344  	return *v, true
  1345  }
  1346  
  1347  // OldDeletedAt returns the old "deleted_at" field's value of the File entity.
  1348  // If the File object wasn't provided to the builder, the object is fetched from the database.
  1349  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1350  func (m *FileMutation) OldDeletedAt(ctx context.Context) (v time.Time, err error) {
  1351  	if !m.op.Is(OpUpdateOne) {
  1352  		return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
  1353  	}
  1354  	if m.id == nil || m.oldValue == nil {
  1355  		return v, errors.New("OldDeletedAt requires an ID field in the mutation")
  1356  	}
  1357  	oldValue, err := m.oldValue(ctx)
  1358  	if err != nil {
  1359  		return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
  1360  	}
  1361  	return oldValue.DeletedAt, nil
  1362  }
  1363  
  1364  // ClearDeletedAt clears the value of the "deleted_at" field.
  1365  func (m *FileMutation) ClearDeletedAt() {
  1366  	m.deleted_at = nil
  1367  	m.clearedFields[file.FieldDeletedAt] = struct{}{}
  1368  }
  1369  
  1370  // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
  1371  func (m *FileMutation) DeletedAtCleared() bool {
  1372  	_, ok := m.clearedFields[file.FieldDeletedAt]
  1373  	return ok
  1374  }
  1375  
  1376  // ResetDeletedAt resets all changes to the "deleted_at" field.
  1377  func (m *FileMutation) ResetDeletedAt() {
  1378  	m.deleted_at = nil
  1379  	delete(m.clearedFields, file.FieldDeletedAt)
  1380  }
  1381  
  1382  // SetDisk sets the "disk" field.
  1383  func (m *FileMutation) SetDisk(s string) {
  1384  	m.disk = &s
  1385  }
  1386  
  1387  // Disk returns the value of the "disk" field in the mutation.
  1388  func (m *FileMutation) Disk() (r string, exists bool) {
  1389  	v := m.disk
  1390  	if v == nil {
  1391  		return
  1392  	}
  1393  	return *v, true
  1394  }
  1395  
  1396  // OldDisk returns the old "disk" field's value of the File entity.
  1397  // If the File object wasn't provided to the builder, the object is fetched from the database.
  1398  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1399  func (m *FileMutation) OldDisk(ctx context.Context) (v string, err error) {
  1400  	if !m.op.Is(OpUpdateOne) {
  1401  		return v, errors.New("OldDisk is only allowed on UpdateOne operations")
  1402  	}
  1403  	if m.id == nil || m.oldValue == nil {
  1404  		return v, errors.New("OldDisk requires an ID field in the mutation")
  1405  	}
  1406  	oldValue, err := m.oldValue(ctx)
  1407  	if err != nil {
  1408  		return v, fmt.Errorf("querying old value for OldDisk: %w", err)
  1409  	}
  1410  	return oldValue.Disk, nil
  1411  }
  1412  
  1413  // ResetDisk resets all changes to the "disk" field.
  1414  func (m *FileMutation) ResetDisk() {
  1415  	m.disk = nil
  1416  }
  1417  
  1418  // SetPath sets the "path" field.
  1419  func (m *FileMutation) SetPath(s string) {
  1420  	m._path = &s
  1421  }
  1422  
  1423  // Path returns the value of the "path" field in the mutation.
  1424  func (m *FileMutation) Path() (r string, exists bool) {
  1425  	v := m._path
  1426  	if v == nil {
  1427  		return
  1428  	}
  1429  	return *v, true
  1430  }
  1431  
  1432  // OldPath returns the old "path" field's value of the File entity.
  1433  // If the File object wasn't provided to the builder, the object is fetched from the database.
  1434  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1435  func (m *FileMutation) OldPath(ctx context.Context) (v string, err error) {
  1436  	if !m.op.Is(OpUpdateOne) {
  1437  		return v, errors.New("OldPath is only allowed on UpdateOne operations")
  1438  	}
  1439  	if m.id == nil || m.oldValue == nil {
  1440  		return v, errors.New("OldPath requires an ID field in the mutation")
  1441  	}
  1442  	oldValue, err := m.oldValue(ctx)
  1443  	if err != nil {
  1444  		return v, fmt.Errorf("querying old value for OldPath: %w", err)
  1445  	}
  1446  	return oldValue.Path, nil
  1447  }
  1448  
  1449  // ResetPath resets all changes to the "path" field.
  1450  func (m *FileMutation) ResetPath() {
  1451  	m._path = nil
  1452  }
  1453  
  1454  // SetType sets the "type" field.
  1455  func (m *FileMutation) SetType(s string) {
  1456  	m._type = &s
  1457  }
  1458  
  1459  // GetType returns the value of the "type" field in the mutation.
  1460  func (m *FileMutation) GetType() (r string, exists bool) {
  1461  	v := m._type
  1462  	if v == nil {
  1463  		return
  1464  	}
  1465  	return *v, true
  1466  }
  1467  
  1468  // OldType returns the old "type" field's value of the File entity.
  1469  // If the File object wasn't provided to the builder, the object is fetched from the database.
  1470  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1471  func (m *FileMutation) OldType(ctx context.Context) (v string, err error) {
  1472  	if !m.op.Is(OpUpdateOne) {
  1473  		return v, errors.New("OldType is only allowed on UpdateOne operations")
  1474  	}
  1475  	if m.id == nil || m.oldValue == nil {
  1476  		return v, errors.New("OldType requires an ID field in the mutation")
  1477  	}
  1478  	oldValue, err := m.oldValue(ctx)
  1479  	if err != nil {
  1480  		return v, fmt.Errorf("querying old value for OldType: %w", err)
  1481  	}
  1482  	return oldValue.Type, nil
  1483  }
  1484  
  1485  // ResetType resets all changes to the "type" field.
  1486  func (m *FileMutation) ResetType() {
  1487  	m._type = nil
  1488  }
  1489  
  1490  // SetSize sets the "size" field.
  1491  func (m *FileMutation) SetSize(i int) {
  1492  	m.size = &i
  1493  	m.addsize = nil
  1494  }
  1495  
  1496  // Size returns the value of the "size" field in the mutation.
  1497  func (m *FileMutation) Size() (r int, exists bool) {
  1498  	v := m.size
  1499  	if v == nil {
  1500  		return
  1501  	}
  1502  	return *v, true
  1503  }
  1504  
  1505  // OldSize returns the old "size" field's value of the File entity.
  1506  // If the File object wasn't provided to the builder, the object is fetched from the database.
  1507  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1508  func (m *FileMutation) OldSize(ctx context.Context) (v int, err error) {
  1509  	if !m.op.Is(OpUpdateOne) {
  1510  		return v, errors.New("OldSize is only allowed on UpdateOne operations")
  1511  	}
  1512  	if m.id == nil || m.oldValue == nil {
  1513  		return v, errors.New("OldSize requires an ID field in the mutation")
  1514  	}
  1515  	oldValue, err := m.oldValue(ctx)
  1516  	if err != nil {
  1517  		return v, fmt.Errorf("querying old value for OldSize: %w", err)
  1518  	}
  1519  	return oldValue.Size, nil
  1520  }
  1521  
  1522  // AddSize adds i to the "size" field.
  1523  func (m *FileMutation) AddSize(i int) {
  1524  	if m.addsize != nil {
  1525  		*m.addsize += i
  1526  	} else {
  1527  		m.addsize = &i
  1528  	}
  1529  }
  1530  
  1531  // AddedSize returns the value that was added to the "size" field in this mutation.
  1532  func (m *FileMutation) AddedSize() (r int, exists bool) {
  1533  	v := m.addsize
  1534  	if v == nil {
  1535  		return
  1536  	}
  1537  	return *v, true
  1538  }
  1539  
  1540  // ResetSize resets all changes to the "size" field.
  1541  func (m *FileMutation) ResetSize() {
  1542  	m.size = nil
  1543  	m.addsize = nil
  1544  }
  1545  
  1546  // SetUserID sets the "user_id" field.
  1547  func (m *FileMutation) SetUserID(i int) {
  1548  	m.user = &i
  1549  }
  1550  
  1551  // UserID returns the value of the "user_id" field in the mutation.
  1552  func (m *FileMutation) UserID() (r int, exists bool) {
  1553  	v := m.user
  1554  	if v == nil {
  1555  		return
  1556  	}
  1557  	return *v, true
  1558  }
  1559  
  1560  // OldUserID returns the old "user_id" field's value of the File entity.
  1561  // If the File object wasn't provided to the builder, the object is fetched from the database.
  1562  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  1563  func (m *FileMutation) OldUserID(ctx context.Context) (v int, err error) {
  1564  	if !m.op.Is(OpUpdateOne) {
  1565  		return v, errors.New("OldUserID is only allowed on UpdateOne operations")
  1566  	}
  1567  	if m.id == nil || m.oldValue == nil {
  1568  		return v, errors.New("OldUserID requires an ID field in the mutation")
  1569  	}
  1570  	oldValue, err := m.oldValue(ctx)
  1571  	if err != nil {
  1572  		return v, fmt.Errorf("querying old value for OldUserID: %w", err)
  1573  	}
  1574  	return oldValue.UserID, nil
  1575  }
  1576  
  1577  // ClearUserID clears the value of the "user_id" field.
  1578  func (m *FileMutation) ClearUserID() {
  1579  	m.user = nil
  1580  	m.clearedFields[file.FieldUserID] = struct{}{}
  1581  }
  1582  
  1583  // UserIDCleared returns if the "user_id" field was cleared in this mutation.
  1584  func (m *FileMutation) UserIDCleared() bool {
  1585  	_, ok := m.clearedFields[file.FieldUserID]
  1586  	return ok
  1587  }
  1588  
  1589  // ResetUserID resets all changes to the "user_id" field.
  1590  func (m *FileMutation) ResetUserID() {
  1591  	m.user = nil
  1592  	delete(m.clearedFields, file.FieldUserID)
  1593  }
  1594  
  1595  // ClearUser clears the "user" edge to the User entity.
  1596  func (m *FileMutation) ClearUser() {
  1597  	m.cleareduser = true
  1598  }
  1599  
  1600  // UserCleared reports if the "user" edge to the User entity was cleared.
  1601  func (m *FileMutation) UserCleared() bool {
  1602  	return m.UserIDCleared() || m.cleareduser
  1603  }
  1604  
  1605  // UserIDs returns the "user" edge IDs in the mutation.
  1606  // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  1607  // UserID instead. It exists only for internal usage by the builders.
  1608  func (m *FileMutation) UserIDs() (ids []int) {
  1609  	if id := m.user; id != nil {
  1610  		ids = append(ids, *id)
  1611  	}
  1612  	return
  1613  }
  1614  
  1615  // ResetUser resets all changes to the "user" edge.
  1616  func (m *FileMutation) ResetUser() {
  1617  	m.user = nil
  1618  	m.cleareduser = false
  1619  }
  1620  
  1621  // AddPostIDs adds the "posts" edge to the Post entity by ids.
  1622  func (m *FileMutation) AddPostIDs(ids ...int) {
  1623  	if m.posts == nil {
  1624  		m.posts = make(map[int]struct{})
  1625  	}
  1626  	for i := range ids {
  1627  		m.posts[ids[i]] = struct{}{}
  1628  	}
  1629  }
  1630  
  1631  // ClearPosts clears the "posts" edge to the Post entity.
  1632  func (m *FileMutation) ClearPosts() {
  1633  	m.clearedposts = true
  1634  }
  1635  
  1636  // PostsCleared reports if the "posts" edge to the Post entity was cleared.
  1637  func (m *FileMutation) PostsCleared() bool {
  1638  	return m.clearedposts
  1639  }
  1640  
  1641  // RemovePostIDs removes the "posts" edge to the Post entity by IDs.
  1642  func (m *FileMutation) RemovePostIDs(ids ...int) {
  1643  	if m.removedposts == nil {
  1644  		m.removedposts = make(map[int]struct{})
  1645  	}
  1646  	for i := range ids {
  1647  		delete(m.posts, ids[i])
  1648  		m.removedposts[ids[i]] = struct{}{}
  1649  	}
  1650  }
  1651  
  1652  // RemovedPosts returns the removed IDs of the "posts" edge to the Post entity.
  1653  func (m *FileMutation) RemovedPostsIDs() (ids []int) {
  1654  	for id := range m.removedposts {
  1655  		ids = append(ids, id)
  1656  	}
  1657  	return
  1658  }
  1659  
  1660  // PostsIDs returns the "posts" edge IDs in the mutation.
  1661  func (m *FileMutation) PostsIDs() (ids []int) {
  1662  	for id := range m.posts {
  1663  		ids = append(ids, id)
  1664  	}
  1665  	return
  1666  }
  1667  
  1668  // ResetPosts resets all changes to the "posts" edge.
  1669  func (m *FileMutation) ResetPosts() {
  1670  	m.posts = nil
  1671  	m.clearedposts = false
  1672  	m.removedposts = nil
  1673  }
  1674  
  1675  // AddPageIDs adds the "pages" edge to the Page entity by ids.
  1676  func (m *FileMutation) AddPageIDs(ids ...int) {
  1677  	if m.pages == nil {
  1678  		m.pages = make(map[int]struct{})
  1679  	}
  1680  	for i := range ids {
  1681  		m.pages[ids[i]] = struct{}{}
  1682  	}
  1683  }
  1684  
  1685  // ClearPages clears the "pages" edge to the Page entity.
  1686  func (m *FileMutation) ClearPages() {
  1687  	m.clearedpages = true
  1688  }
  1689  
  1690  // PagesCleared reports if the "pages" edge to the Page entity was cleared.
  1691  func (m *FileMutation) PagesCleared() bool {
  1692  	return m.clearedpages
  1693  }
  1694  
  1695  // RemovePageIDs removes the "pages" edge to the Page entity by IDs.
  1696  func (m *FileMutation) RemovePageIDs(ids ...int) {
  1697  	if m.removedpages == nil {
  1698  		m.removedpages = make(map[int]struct{})
  1699  	}
  1700  	for i := range ids {
  1701  		delete(m.pages, ids[i])
  1702  		m.removedpages[ids[i]] = struct{}{}
  1703  	}
  1704  }
  1705  
  1706  // RemovedPages returns the removed IDs of the "pages" edge to the Page entity.
  1707  func (m *FileMutation) RemovedPagesIDs() (ids []int) {
  1708  	for id := range m.removedpages {
  1709  		ids = append(ids, id)
  1710  	}
  1711  	return
  1712  }
  1713  
  1714  // PagesIDs returns the "pages" edge IDs in the mutation.
  1715  func (m *FileMutation) PagesIDs() (ids []int) {
  1716  	for id := range m.pages {
  1717  		ids = append(ids, id)
  1718  	}
  1719  	return
  1720  }
  1721  
  1722  // ResetPages resets all changes to the "pages" edge.
  1723  func (m *FileMutation) ResetPages() {
  1724  	m.pages = nil
  1725  	m.clearedpages = false
  1726  	m.removedpages = nil
  1727  }
  1728  
  1729  // AddUserAvatarIDs adds the "user_avatars" edge to the User entity by ids.
  1730  func (m *FileMutation) AddUserAvatarIDs(ids ...int) {
  1731  	if m.user_avatars == nil {
  1732  		m.user_avatars = make(map[int]struct{})
  1733  	}
  1734  	for i := range ids {
  1735  		m.user_avatars[ids[i]] = struct{}{}
  1736  	}
  1737  }
  1738  
  1739  // ClearUserAvatars clears the "user_avatars" edge to the User entity.
  1740  func (m *FileMutation) ClearUserAvatars() {
  1741  	m.cleareduser_avatars = true
  1742  }
  1743  
  1744  // UserAvatarsCleared reports if the "user_avatars" edge to the User entity was cleared.
  1745  func (m *FileMutation) UserAvatarsCleared() bool {
  1746  	return m.cleareduser_avatars
  1747  }
  1748  
  1749  // RemoveUserAvatarIDs removes the "user_avatars" edge to the User entity by IDs.
  1750  func (m *FileMutation) RemoveUserAvatarIDs(ids ...int) {
  1751  	if m.removeduser_avatars == nil {
  1752  		m.removeduser_avatars = make(map[int]struct{})
  1753  	}
  1754  	for i := range ids {
  1755  		delete(m.user_avatars, ids[i])
  1756  		m.removeduser_avatars[ids[i]] = struct{}{}
  1757  	}
  1758  }
  1759  
  1760  // RemovedUserAvatars returns the removed IDs of the "user_avatars" edge to the User entity.
  1761  func (m *FileMutation) RemovedUserAvatarsIDs() (ids []int) {
  1762  	for id := range m.removeduser_avatars {
  1763  		ids = append(ids, id)
  1764  	}
  1765  	return
  1766  }
  1767  
  1768  // UserAvatarsIDs returns the "user_avatars" edge IDs in the mutation.
  1769  func (m *FileMutation) UserAvatarsIDs() (ids []int) {
  1770  	for id := range m.user_avatars {
  1771  		ids = append(ids, id)
  1772  	}
  1773  	return
  1774  }
  1775  
  1776  // ResetUserAvatars resets all changes to the "user_avatars" edge.
  1777  func (m *FileMutation) ResetUserAvatars() {
  1778  	m.user_avatars = nil
  1779  	m.cleareduser_avatars = false
  1780  	m.removeduser_avatars = nil
  1781  }
  1782  
  1783  // Where appends a list predicates to the FileMutation builder.
  1784  func (m *FileMutation) Where(ps ...predicate.File) {
  1785  	m.predicates = append(m.predicates, ps...)
  1786  }
  1787  
  1788  // Op returns the operation name.
  1789  func (m *FileMutation) Op() Op {
  1790  	return m.op
  1791  }
  1792  
  1793  // Type returns the node type of this mutation (File).
  1794  func (m *FileMutation) Type() string {
  1795  	return m.typ
  1796  }
  1797  
  1798  // Fields returns all fields that were changed during this mutation. Note that in
  1799  // order to get all numeric fields that were incremented/decremented, call
  1800  // AddedFields().
  1801  func (m *FileMutation) Fields() []string {
  1802  	fields := make([]string, 0, 8)
  1803  	if m.created_at != nil {
  1804  		fields = append(fields, file.FieldCreatedAt)
  1805  	}
  1806  	if m.updated_at != nil {
  1807  		fields = append(fields, file.FieldUpdatedAt)
  1808  	}
  1809  	if m.deleted_at != nil {
  1810  		fields = append(fields, file.FieldDeletedAt)
  1811  	}
  1812  	if m.disk != nil {
  1813  		fields = append(fields, file.FieldDisk)
  1814  	}
  1815  	if m._path != nil {
  1816  		fields = append(fields, file.FieldPath)
  1817  	}
  1818  	if m._type != nil {
  1819  		fields = append(fields, file.FieldType)
  1820  	}
  1821  	if m.size != nil {
  1822  		fields = append(fields, file.FieldSize)
  1823  	}
  1824  	if m.user != nil {
  1825  		fields = append(fields, file.FieldUserID)
  1826  	}
  1827  	return fields
  1828  }
  1829  
  1830  // Field returns the value of a field with the given name. The second boolean
  1831  // return value indicates that this field was not set, or was not defined in the
  1832  // schema.
  1833  func (m *FileMutation) Field(name string) (ent.Value, bool) {
  1834  	switch name {
  1835  	case file.FieldCreatedAt:
  1836  		return m.CreatedAt()
  1837  	case file.FieldUpdatedAt:
  1838  		return m.UpdatedAt()
  1839  	case file.FieldDeletedAt:
  1840  		return m.DeletedAt()
  1841  	case file.FieldDisk:
  1842  		return m.Disk()
  1843  	case file.FieldPath:
  1844  		return m.Path()
  1845  	case file.FieldType:
  1846  		return m.GetType()
  1847  	case file.FieldSize:
  1848  		return m.Size()
  1849  	case file.FieldUserID:
  1850  		return m.UserID()
  1851  	}
  1852  	return nil, false
  1853  }
  1854  
  1855  // OldField returns the old value of the field from the database. An error is
  1856  // returned if the mutation operation is not UpdateOne, or the query to the
  1857  // database failed.
  1858  func (m *FileMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  1859  	switch name {
  1860  	case file.FieldCreatedAt:
  1861  		return m.OldCreatedAt(ctx)
  1862  	case file.FieldUpdatedAt:
  1863  		return m.OldUpdatedAt(ctx)
  1864  	case file.FieldDeletedAt:
  1865  		return m.OldDeletedAt(ctx)
  1866  	case file.FieldDisk:
  1867  		return m.OldDisk(ctx)
  1868  	case file.FieldPath:
  1869  		return m.OldPath(ctx)
  1870  	case file.FieldType:
  1871  		return m.OldType(ctx)
  1872  	case file.FieldSize:
  1873  		return m.OldSize(ctx)
  1874  	case file.FieldUserID:
  1875  		return m.OldUserID(ctx)
  1876  	}
  1877  	return nil, fmt.Errorf("unknown File field %s", name)
  1878  }
  1879  
  1880  // SetField sets the value of a field with the given name. It returns an error if
  1881  // the field is not defined in the schema, or if the type mismatched the field
  1882  // type.
  1883  func (m *FileMutation) SetField(name string, value ent.Value) error {
  1884  	switch name {
  1885  	case file.FieldCreatedAt:
  1886  		v, ok := value.(time.Time)
  1887  		if !ok {
  1888  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  1889  		}
  1890  		m.SetCreatedAt(v)
  1891  		return nil
  1892  	case file.FieldUpdatedAt:
  1893  		v, ok := value.(time.Time)
  1894  		if !ok {
  1895  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  1896  		}
  1897  		m.SetUpdatedAt(v)
  1898  		return nil
  1899  	case file.FieldDeletedAt:
  1900  		v, ok := value.(time.Time)
  1901  		if !ok {
  1902  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  1903  		}
  1904  		m.SetDeletedAt(v)
  1905  		return nil
  1906  	case file.FieldDisk:
  1907  		v, ok := value.(string)
  1908  		if !ok {
  1909  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  1910  		}
  1911  		m.SetDisk(v)
  1912  		return nil
  1913  	case file.FieldPath:
  1914  		v, ok := value.(string)
  1915  		if !ok {
  1916  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  1917  		}
  1918  		m.SetPath(v)
  1919  		return nil
  1920  	case file.FieldType:
  1921  		v, ok := value.(string)
  1922  		if !ok {
  1923  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  1924  		}
  1925  		m.SetType(v)
  1926  		return nil
  1927  	case file.FieldSize:
  1928  		v, ok := value.(int)
  1929  		if !ok {
  1930  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  1931  		}
  1932  		m.SetSize(v)
  1933  		return nil
  1934  	case file.FieldUserID:
  1935  		v, ok := value.(int)
  1936  		if !ok {
  1937  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  1938  		}
  1939  		m.SetUserID(v)
  1940  		return nil
  1941  	}
  1942  	return fmt.Errorf("unknown File field %s", name)
  1943  }
  1944  
  1945  // AddedFields returns all numeric fields that were incremented/decremented during
  1946  // this mutation.
  1947  func (m *FileMutation) AddedFields() []string {
  1948  	var fields []string
  1949  	if m.addsize != nil {
  1950  		fields = append(fields, file.FieldSize)
  1951  	}
  1952  	return fields
  1953  }
  1954  
  1955  // AddedField returns the numeric value that was incremented/decremented on a field
  1956  // with the given name. The second boolean return value indicates that this field
  1957  // was not set, or was not defined in the schema.
  1958  func (m *FileMutation) AddedField(name string) (ent.Value, bool) {
  1959  	switch name {
  1960  	case file.FieldSize:
  1961  		return m.AddedSize()
  1962  	}
  1963  	return nil, false
  1964  }
  1965  
  1966  // AddField adds the value to the field with the given name. It returns an error if
  1967  // the field is not defined in the schema, or if the type mismatched the field
  1968  // type.
  1969  func (m *FileMutation) AddField(name string, value ent.Value) error {
  1970  	switch name {
  1971  	case file.FieldSize:
  1972  		v, ok := value.(int)
  1973  		if !ok {
  1974  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  1975  		}
  1976  		m.AddSize(v)
  1977  		return nil
  1978  	}
  1979  	return fmt.Errorf("unknown File numeric field %s", name)
  1980  }
  1981  
  1982  // ClearedFields returns all nullable fields that were cleared during this
  1983  // mutation.
  1984  func (m *FileMutation) ClearedFields() []string {
  1985  	var fields []string
  1986  	if m.FieldCleared(file.FieldDeletedAt) {
  1987  		fields = append(fields, file.FieldDeletedAt)
  1988  	}
  1989  	if m.FieldCleared(file.FieldUserID) {
  1990  		fields = append(fields, file.FieldUserID)
  1991  	}
  1992  	return fields
  1993  }
  1994  
  1995  // FieldCleared returns a boolean indicating if a field with the given name was
  1996  // cleared in this mutation.
  1997  func (m *FileMutation) FieldCleared(name string) bool {
  1998  	_, ok := m.clearedFields[name]
  1999  	return ok
  2000  }
  2001  
  2002  // ClearField clears the value of the field with the given name. It returns an
  2003  // error if the field is not defined in the schema.
  2004  func (m *FileMutation) ClearField(name string) error {
  2005  	switch name {
  2006  	case file.FieldDeletedAt:
  2007  		m.ClearDeletedAt()
  2008  		return nil
  2009  	case file.FieldUserID:
  2010  		m.ClearUserID()
  2011  		return nil
  2012  	}
  2013  	return fmt.Errorf("unknown File nullable field %s", name)
  2014  }
  2015  
  2016  // ResetField resets all changes in the mutation for the field with the given name.
  2017  // It returns an error if the field is not defined in the schema.
  2018  func (m *FileMutation) ResetField(name string) error {
  2019  	switch name {
  2020  	case file.FieldCreatedAt:
  2021  		m.ResetCreatedAt()
  2022  		return nil
  2023  	case file.FieldUpdatedAt:
  2024  		m.ResetUpdatedAt()
  2025  		return nil
  2026  	case file.FieldDeletedAt:
  2027  		m.ResetDeletedAt()
  2028  		return nil
  2029  	case file.FieldDisk:
  2030  		m.ResetDisk()
  2031  		return nil
  2032  	case file.FieldPath:
  2033  		m.ResetPath()
  2034  		return nil
  2035  	case file.FieldType:
  2036  		m.ResetType()
  2037  		return nil
  2038  	case file.FieldSize:
  2039  		m.ResetSize()
  2040  		return nil
  2041  	case file.FieldUserID:
  2042  		m.ResetUserID()
  2043  		return nil
  2044  	}
  2045  	return fmt.Errorf("unknown File field %s", name)
  2046  }
  2047  
  2048  // AddedEdges returns all edge names that were set/added in this mutation.
  2049  func (m *FileMutation) AddedEdges() []string {
  2050  	edges := make([]string, 0, 4)
  2051  	if m.user != nil {
  2052  		edges = append(edges, file.EdgeUser)
  2053  	}
  2054  	if m.posts != nil {
  2055  		edges = append(edges, file.EdgePosts)
  2056  	}
  2057  	if m.pages != nil {
  2058  		edges = append(edges, file.EdgePages)
  2059  	}
  2060  	if m.user_avatars != nil {
  2061  		edges = append(edges, file.EdgeUserAvatars)
  2062  	}
  2063  	return edges
  2064  }
  2065  
  2066  // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  2067  // name in this mutation.
  2068  func (m *FileMutation) AddedIDs(name string) []ent.Value {
  2069  	switch name {
  2070  	case file.EdgeUser:
  2071  		if id := m.user; id != nil {
  2072  			return []ent.Value{*id}
  2073  		}
  2074  	case file.EdgePosts:
  2075  		ids := make([]ent.Value, 0, len(m.posts))
  2076  		for id := range m.posts {
  2077  			ids = append(ids, id)
  2078  		}
  2079  		return ids
  2080  	case file.EdgePages:
  2081  		ids := make([]ent.Value, 0, len(m.pages))
  2082  		for id := range m.pages {
  2083  			ids = append(ids, id)
  2084  		}
  2085  		return ids
  2086  	case file.EdgeUserAvatars:
  2087  		ids := make([]ent.Value, 0, len(m.user_avatars))
  2088  		for id := range m.user_avatars {
  2089  			ids = append(ids, id)
  2090  		}
  2091  		return ids
  2092  	}
  2093  	return nil
  2094  }
  2095  
  2096  // RemovedEdges returns all edge names that were removed in this mutation.
  2097  func (m *FileMutation) RemovedEdges() []string {
  2098  	edges := make([]string, 0, 4)
  2099  	if m.removedposts != nil {
  2100  		edges = append(edges, file.EdgePosts)
  2101  	}
  2102  	if m.removedpages != nil {
  2103  		edges = append(edges, file.EdgePages)
  2104  	}
  2105  	if m.removeduser_avatars != nil {
  2106  		edges = append(edges, file.EdgeUserAvatars)
  2107  	}
  2108  	return edges
  2109  }
  2110  
  2111  // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  2112  // the given name in this mutation.
  2113  func (m *FileMutation) RemovedIDs(name string) []ent.Value {
  2114  	switch name {
  2115  	case file.EdgePosts:
  2116  		ids := make([]ent.Value, 0, len(m.removedposts))
  2117  		for id := range m.removedposts {
  2118  			ids = append(ids, id)
  2119  		}
  2120  		return ids
  2121  	case file.EdgePages:
  2122  		ids := make([]ent.Value, 0, len(m.removedpages))
  2123  		for id := range m.removedpages {
  2124  			ids = append(ids, id)
  2125  		}
  2126  		return ids
  2127  	case file.EdgeUserAvatars:
  2128  		ids := make([]ent.Value, 0, len(m.removeduser_avatars))
  2129  		for id := range m.removeduser_avatars {
  2130  			ids = append(ids, id)
  2131  		}
  2132  		return ids
  2133  	}
  2134  	return nil
  2135  }
  2136  
  2137  // ClearedEdges returns all edge names that were cleared in this mutation.
  2138  func (m *FileMutation) ClearedEdges() []string {
  2139  	edges := make([]string, 0, 4)
  2140  	if m.cleareduser {
  2141  		edges = append(edges, file.EdgeUser)
  2142  	}
  2143  	if m.clearedposts {
  2144  		edges = append(edges, file.EdgePosts)
  2145  	}
  2146  	if m.clearedpages {
  2147  		edges = append(edges, file.EdgePages)
  2148  	}
  2149  	if m.cleareduser_avatars {
  2150  		edges = append(edges, file.EdgeUserAvatars)
  2151  	}
  2152  	return edges
  2153  }
  2154  
  2155  // EdgeCleared returns a boolean which indicates if the edge with the given name
  2156  // was cleared in this mutation.
  2157  func (m *FileMutation) EdgeCleared(name string) bool {
  2158  	switch name {
  2159  	case file.EdgeUser:
  2160  		return m.cleareduser
  2161  	case file.EdgePosts:
  2162  		return m.clearedposts
  2163  	case file.EdgePages:
  2164  		return m.clearedpages
  2165  	case file.EdgeUserAvatars:
  2166  		return m.cleareduser_avatars
  2167  	}
  2168  	return false
  2169  }
  2170  
  2171  // ClearEdge clears the value of the edge with the given name. It returns an error
  2172  // if that edge is not defined in the schema.
  2173  func (m *FileMutation) ClearEdge(name string) error {
  2174  	switch name {
  2175  	case file.EdgeUser:
  2176  		m.ClearUser()
  2177  		return nil
  2178  	}
  2179  	return fmt.Errorf("unknown File unique edge %s", name)
  2180  }
  2181  
  2182  // ResetEdge resets all changes to the edge with the given name in this mutation.
  2183  // It returns an error if the edge is not defined in the schema.
  2184  func (m *FileMutation) ResetEdge(name string) error {
  2185  	switch name {
  2186  	case file.EdgeUser:
  2187  		m.ResetUser()
  2188  		return nil
  2189  	case file.EdgePosts:
  2190  		m.ResetPosts()
  2191  		return nil
  2192  	case file.EdgePages:
  2193  		m.ResetPages()
  2194  		return nil
  2195  	case file.EdgeUserAvatars:
  2196  		m.ResetUserAvatars()
  2197  		return nil
  2198  	}
  2199  	return fmt.Errorf("unknown File edge %s", name)
  2200  }
  2201  
  2202  // PageMutation represents an operation that mutates the Page nodes in the graph.
  2203  type PageMutation struct {
  2204  	config
  2205  	op                    Op
  2206  	typ                   string
  2207  	id                    *int
  2208  	created_at            *time.Time
  2209  	updated_at            *time.Time
  2210  	deleted_at            *time.Time
  2211  	name                  *string
  2212  	slug                  *string
  2213  	content               *string
  2214  	content_html          *string
  2215  	draft                 *bool
  2216  	clearedFields         map[string]struct{}
  2217  	featured_image        *int
  2218  	clearedfeatured_image bool
  2219  	done                  bool
  2220  	oldValue              func(context.Context) (*Page, error)
  2221  	predicates            []predicate.Page
  2222  }
  2223  
  2224  var _ ent.Mutation = (*PageMutation)(nil)
  2225  
  2226  // pageOption allows management of the mutation configuration using functional options.
  2227  type pageOption func(*PageMutation)
  2228  
  2229  // newPageMutation creates new mutation for the Page entity.
  2230  func newPageMutation(c config, op Op, opts ...pageOption) *PageMutation {
  2231  	m := &PageMutation{
  2232  		config:        c,
  2233  		op:            op,
  2234  		typ:           TypePage,
  2235  		clearedFields: make(map[string]struct{}),
  2236  	}
  2237  	for _, opt := range opts {
  2238  		opt(m)
  2239  	}
  2240  	return m
  2241  }
  2242  
  2243  // withPageID sets the ID field of the mutation.
  2244  func withPageID(id int) pageOption {
  2245  	return func(m *PageMutation) {
  2246  		var (
  2247  			err   error
  2248  			once  sync.Once
  2249  			value *Page
  2250  		)
  2251  		m.oldValue = func(ctx context.Context) (*Page, error) {
  2252  			once.Do(func() {
  2253  				if m.done {
  2254  					err = errors.New("querying old values post mutation is not allowed")
  2255  				} else {
  2256  					value, err = m.Client().Page.Get(ctx, id)
  2257  				}
  2258  			})
  2259  			return value, err
  2260  		}
  2261  		m.id = &id
  2262  	}
  2263  }
  2264  
  2265  // withPage sets the old Page of the mutation.
  2266  func withPage(node *Page) pageOption {
  2267  	return func(m *PageMutation) {
  2268  		m.oldValue = func(context.Context) (*Page, error) {
  2269  			return node, nil
  2270  		}
  2271  		m.id = &node.ID
  2272  	}
  2273  }
  2274  
  2275  // Client returns a new `ent.Client` from the mutation. If the mutation was
  2276  // executed in a transaction (ent.Tx), a transactional client is returned.
  2277  func (m PageMutation) Client() *Client {
  2278  	client := &Client{config: m.config}
  2279  	client.init()
  2280  	return client
  2281  }
  2282  
  2283  // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  2284  // it returns an error otherwise.
  2285  func (m PageMutation) Tx() (*Tx, error) {
  2286  	if _, ok := m.driver.(*txDriver); !ok {
  2287  		return nil, errors.New("ent: mutation is not running in a transaction")
  2288  	}
  2289  	tx := &Tx{config: m.config}
  2290  	tx.init()
  2291  	return tx, nil
  2292  }
  2293  
  2294  // ID returns the ID value in the mutation. Note that the ID is only available
  2295  // if it was provided to the builder or after it was returned from the database.
  2296  func (m *PageMutation) ID() (id int, exists bool) {
  2297  	if m.id == nil {
  2298  		return
  2299  	}
  2300  	return *m.id, true
  2301  }
  2302  
  2303  // IDs queries the database and returns the entity ids that match the mutation's predicate.
  2304  // That means, if the mutation is applied within a transaction with an isolation level such
  2305  // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  2306  // or updated by the mutation.
  2307  func (m *PageMutation) IDs(ctx context.Context) ([]int, error) {
  2308  	switch {
  2309  	case m.op.Is(OpUpdateOne | OpDeleteOne):
  2310  		id, exists := m.ID()
  2311  		if exists {
  2312  			return []int{id}, nil
  2313  		}
  2314  		fallthrough
  2315  	case m.op.Is(OpUpdate | OpDelete):
  2316  		return m.Client().Page.Query().Where(m.predicates...).IDs(ctx)
  2317  	default:
  2318  		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  2319  	}
  2320  }
  2321  
  2322  // SetCreatedAt sets the "created_at" field.
  2323  func (m *PageMutation) SetCreatedAt(t time.Time) {
  2324  	m.created_at = &t
  2325  }
  2326  
  2327  // CreatedAt returns the value of the "created_at" field in the mutation.
  2328  func (m *PageMutation) CreatedAt() (r time.Time, exists bool) {
  2329  	v := m.created_at
  2330  	if v == nil {
  2331  		return
  2332  	}
  2333  	return *v, true
  2334  }
  2335  
  2336  // OldCreatedAt returns the old "created_at" field's value of the Page entity.
  2337  // If the Page object wasn't provided to the builder, the object is fetched from the database.
  2338  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2339  func (m *PageMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  2340  	if !m.op.Is(OpUpdateOne) {
  2341  		return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  2342  	}
  2343  	if m.id == nil || m.oldValue == nil {
  2344  		return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  2345  	}
  2346  	oldValue, err := m.oldValue(ctx)
  2347  	if err != nil {
  2348  		return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  2349  	}
  2350  	return oldValue.CreatedAt, nil
  2351  }
  2352  
  2353  // ResetCreatedAt resets all changes to the "created_at" field.
  2354  func (m *PageMutation) ResetCreatedAt() {
  2355  	m.created_at = nil
  2356  }
  2357  
  2358  // SetUpdatedAt sets the "updated_at" field.
  2359  func (m *PageMutation) SetUpdatedAt(t time.Time) {
  2360  	m.updated_at = &t
  2361  }
  2362  
  2363  // UpdatedAt returns the value of the "updated_at" field in the mutation.
  2364  func (m *PageMutation) UpdatedAt() (r time.Time, exists bool) {
  2365  	v := m.updated_at
  2366  	if v == nil {
  2367  		return
  2368  	}
  2369  	return *v, true
  2370  }
  2371  
  2372  // OldUpdatedAt returns the old "updated_at" field's value of the Page entity.
  2373  // If the Page object wasn't provided to the builder, the object is fetched from the database.
  2374  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2375  func (m *PageMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  2376  	if !m.op.Is(OpUpdateOne) {
  2377  		return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  2378  	}
  2379  	if m.id == nil || m.oldValue == nil {
  2380  		return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  2381  	}
  2382  	oldValue, err := m.oldValue(ctx)
  2383  	if err != nil {
  2384  		return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  2385  	}
  2386  	return oldValue.UpdatedAt, nil
  2387  }
  2388  
  2389  // ResetUpdatedAt resets all changes to the "updated_at" field.
  2390  func (m *PageMutation) ResetUpdatedAt() {
  2391  	m.updated_at = nil
  2392  }
  2393  
  2394  // SetDeletedAt sets the "deleted_at" field.
  2395  func (m *PageMutation) SetDeletedAt(t time.Time) {
  2396  	m.deleted_at = &t
  2397  }
  2398  
  2399  // DeletedAt returns the value of the "deleted_at" field in the mutation.
  2400  func (m *PageMutation) DeletedAt() (r time.Time, exists bool) {
  2401  	v := m.deleted_at
  2402  	if v == nil {
  2403  		return
  2404  	}
  2405  	return *v, true
  2406  }
  2407  
  2408  // OldDeletedAt returns the old "deleted_at" field's value of the Page entity.
  2409  // If the Page object wasn't provided to the builder, the object is fetched from the database.
  2410  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2411  func (m *PageMutation) OldDeletedAt(ctx context.Context) (v time.Time, err error) {
  2412  	if !m.op.Is(OpUpdateOne) {
  2413  		return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
  2414  	}
  2415  	if m.id == nil || m.oldValue == nil {
  2416  		return v, errors.New("OldDeletedAt requires an ID field in the mutation")
  2417  	}
  2418  	oldValue, err := m.oldValue(ctx)
  2419  	if err != nil {
  2420  		return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
  2421  	}
  2422  	return oldValue.DeletedAt, nil
  2423  }
  2424  
  2425  // ClearDeletedAt clears the value of the "deleted_at" field.
  2426  func (m *PageMutation) ClearDeletedAt() {
  2427  	m.deleted_at = nil
  2428  	m.clearedFields[page.FieldDeletedAt] = struct{}{}
  2429  }
  2430  
  2431  // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
  2432  func (m *PageMutation) DeletedAtCleared() bool {
  2433  	_, ok := m.clearedFields[page.FieldDeletedAt]
  2434  	return ok
  2435  }
  2436  
  2437  // ResetDeletedAt resets all changes to the "deleted_at" field.
  2438  func (m *PageMutation) ResetDeletedAt() {
  2439  	m.deleted_at = nil
  2440  	delete(m.clearedFields, page.FieldDeletedAt)
  2441  }
  2442  
  2443  // SetName sets the "name" field.
  2444  func (m *PageMutation) SetName(s string) {
  2445  	m.name = &s
  2446  }
  2447  
  2448  // Name returns the value of the "name" field in the mutation.
  2449  func (m *PageMutation) Name() (r string, exists bool) {
  2450  	v := m.name
  2451  	if v == nil {
  2452  		return
  2453  	}
  2454  	return *v, true
  2455  }
  2456  
  2457  // OldName returns the old "name" field's value of the Page entity.
  2458  // If the Page object wasn't provided to the builder, the object is fetched from the database.
  2459  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2460  func (m *PageMutation) OldName(ctx context.Context) (v string, err error) {
  2461  	if !m.op.Is(OpUpdateOne) {
  2462  		return v, errors.New("OldName is only allowed on UpdateOne operations")
  2463  	}
  2464  	if m.id == nil || m.oldValue == nil {
  2465  		return v, errors.New("OldName requires an ID field in the mutation")
  2466  	}
  2467  	oldValue, err := m.oldValue(ctx)
  2468  	if err != nil {
  2469  		return v, fmt.Errorf("querying old value for OldName: %w", err)
  2470  	}
  2471  	return oldValue.Name, nil
  2472  }
  2473  
  2474  // ResetName resets all changes to the "name" field.
  2475  func (m *PageMutation) ResetName() {
  2476  	m.name = nil
  2477  }
  2478  
  2479  // SetSlug sets the "slug" field.
  2480  func (m *PageMutation) SetSlug(s string) {
  2481  	m.slug = &s
  2482  }
  2483  
  2484  // Slug returns the value of the "slug" field in the mutation.
  2485  func (m *PageMutation) Slug() (r string, exists bool) {
  2486  	v := m.slug
  2487  	if v == nil {
  2488  		return
  2489  	}
  2490  	return *v, true
  2491  }
  2492  
  2493  // OldSlug returns the old "slug" field's value of the Page entity.
  2494  // If the Page object wasn't provided to the builder, the object is fetched from the database.
  2495  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2496  func (m *PageMutation) OldSlug(ctx context.Context) (v string, err error) {
  2497  	if !m.op.Is(OpUpdateOne) {
  2498  		return v, errors.New("OldSlug is only allowed on UpdateOne operations")
  2499  	}
  2500  	if m.id == nil || m.oldValue == nil {
  2501  		return v, errors.New("OldSlug requires an ID field in the mutation")
  2502  	}
  2503  	oldValue, err := m.oldValue(ctx)
  2504  	if err != nil {
  2505  		return v, fmt.Errorf("querying old value for OldSlug: %w", err)
  2506  	}
  2507  	return oldValue.Slug, nil
  2508  }
  2509  
  2510  // ResetSlug resets all changes to the "slug" field.
  2511  func (m *PageMutation) ResetSlug() {
  2512  	m.slug = nil
  2513  }
  2514  
  2515  // SetContent sets the "content" field.
  2516  func (m *PageMutation) SetContent(s string) {
  2517  	m.content = &s
  2518  }
  2519  
  2520  // Content returns the value of the "content" field in the mutation.
  2521  func (m *PageMutation) Content() (r string, exists bool) {
  2522  	v := m.content
  2523  	if v == nil {
  2524  		return
  2525  	}
  2526  	return *v, true
  2527  }
  2528  
  2529  // OldContent returns the old "content" field's value of the Page entity.
  2530  // If the Page object wasn't provided to the builder, the object is fetched from the database.
  2531  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2532  func (m *PageMutation) OldContent(ctx context.Context) (v string, err error) {
  2533  	if !m.op.Is(OpUpdateOne) {
  2534  		return v, errors.New("OldContent is only allowed on UpdateOne operations")
  2535  	}
  2536  	if m.id == nil || m.oldValue == nil {
  2537  		return v, errors.New("OldContent requires an ID field in the mutation")
  2538  	}
  2539  	oldValue, err := m.oldValue(ctx)
  2540  	if err != nil {
  2541  		return v, fmt.Errorf("querying old value for OldContent: %w", err)
  2542  	}
  2543  	return oldValue.Content, nil
  2544  }
  2545  
  2546  // ResetContent resets all changes to the "content" field.
  2547  func (m *PageMutation) ResetContent() {
  2548  	m.content = nil
  2549  }
  2550  
  2551  // SetContentHTML sets the "content_html" field.
  2552  func (m *PageMutation) SetContentHTML(s string) {
  2553  	m.content_html = &s
  2554  }
  2555  
  2556  // ContentHTML returns the value of the "content_html" field in the mutation.
  2557  func (m *PageMutation) ContentHTML() (r string, exists bool) {
  2558  	v := m.content_html
  2559  	if v == nil {
  2560  		return
  2561  	}
  2562  	return *v, true
  2563  }
  2564  
  2565  // OldContentHTML returns the old "content_html" field's value of the Page entity.
  2566  // If the Page object wasn't provided to the builder, the object is fetched from the database.
  2567  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2568  func (m *PageMutation) OldContentHTML(ctx context.Context) (v string, err error) {
  2569  	if !m.op.Is(OpUpdateOne) {
  2570  		return v, errors.New("OldContentHTML is only allowed on UpdateOne operations")
  2571  	}
  2572  	if m.id == nil || m.oldValue == nil {
  2573  		return v, errors.New("OldContentHTML requires an ID field in the mutation")
  2574  	}
  2575  	oldValue, err := m.oldValue(ctx)
  2576  	if err != nil {
  2577  		return v, fmt.Errorf("querying old value for OldContentHTML: %w", err)
  2578  	}
  2579  	return oldValue.ContentHTML, nil
  2580  }
  2581  
  2582  // ResetContentHTML resets all changes to the "content_html" field.
  2583  func (m *PageMutation) ResetContentHTML() {
  2584  	m.content_html = nil
  2585  }
  2586  
  2587  // SetDraft sets the "draft" field.
  2588  func (m *PageMutation) SetDraft(b bool) {
  2589  	m.draft = &b
  2590  }
  2591  
  2592  // Draft returns the value of the "draft" field in the mutation.
  2593  func (m *PageMutation) Draft() (r bool, exists bool) {
  2594  	v := m.draft
  2595  	if v == nil {
  2596  		return
  2597  	}
  2598  	return *v, true
  2599  }
  2600  
  2601  // OldDraft returns the old "draft" field's value of the Page entity.
  2602  // If the Page object wasn't provided to the builder, the object is fetched from the database.
  2603  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2604  func (m *PageMutation) OldDraft(ctx context.Context) (v bool, err error) {
  2605  	if !m.op.Is(OpUpdateOne) {
  2606  		return v, errors.New("OldDraft is only allowed on UpdateOne operations")
  2607  	}
  2608  	if m.id == nil || m.oldValue == nil {
  2609  		return v, errors.New("OldDraft requires an ID field in the mutation")
  2610  	}
  2611  	oldValue, err := m.oldValue(ctx)
  2612  	if err != nil {
  2613  		return v, fmt.Errorf("querying old value for OldDraft: %w", err)
  2614  	}
  2615  	return oldValue.Draft, nil
  2616  }
  2617  
  2618  // ClearDraft clears the value of the "draft" field.
  2619  func (m *PageMutation) ClearDraft() {
  2620  	m.draft = nil
  2621  	m.clearedFields[page.FieldDraft] = struct{}{}
  2622  }
  2623  
  2624  // DraftCleared returns if the "draft" field was cleared in this mutation.
  2625  func (m *PageMutation) DraftCleared() bool {
  2626  	_, ok := m.clearedFields[page.FieldDraft]
  2627  	return ok
  2628  }
  2629  
  2630  // ResetDraft resets all changes to the "draft" field.
  2631  func (m *PageMutation) ResetDraft() {
  2632  	m.draft = nil
  2633  	delete(m.clearedFields, page.FieldDraft)
  2634  }
  2635  
  2636  // SetFeaturedImageID sets the "featured_image_id" field.
  2637  func (m *PageMutation) SetFeaturedImageID(i int) {
  2638  	m.featured_image = &i
  2639  }
  2640  
  2641  // FeaturedImageID returns the value of the "featured_image_id" field in the mutation.
  2642  func (m *PageMutation) FeaturedImageID() (r int, exists bool) {
  2643  	v := m.featured_image
  2644  	if v == nil {
  2645  		return
  2646  	}
  2647  	return *v, true
  2648  }
  2649  
  2650  // OldFeaturedImageID returns the old "featured_image_id" field's value of the Page entity.
  2651  // If the Page object wasn't provided to the builder, the object is fetched from the database.
  2652  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  2653  func (m *PageMutation) OldFeaturedImageID(ctx context.Context) (v int, err error) {
  2654  	if !m.op.Is(OpUpdateOne) {
  2655  		return v, errors.New("OldFeaturedImageID is only allowed on UpdateOne operations")
  2656  	}
  2657  	if m.id == nil || m.oldValue == nil {
  2658  		return v, errors.New("OldFeaturedImageID requires an ID field in the mutation")
  2659  	}
  2660  	oldValue, err := m.oldValue(ctx)
  2661  	if err != nil {
  2662  		return v, fmt.Errorf("querying old value for OldFeaturedImageID: %w", err)
  2663  	}
  2664  	return oldValue.FeaturedImageID, nil
  2665  }
  2666  
  2667  // ClearFeaturedImageID clears the value of the "featured_image_id" field.
  2668  func (m *PageMutation) ClearFeaturedImageID() {
  2669  	m.featured_image = nil
  2670  	m.clearedFields[page.FieldFeaturedImageID] = struct{}{}
  2671  }
  2672  
  2673  // FeaturedImageIDCleared returns if the "featured_image_id" field was cleared in this mutation.
  2674  func (m *PageMutation) FeaturedImageIDCleared() bool {
  2675  	_, ok := m.clearedFields[page.FieldFeaturedImageID]
  2676  	return ok
  2677  }
  2678  
  2679  // ResetFeaturedImageID resets all changes to the "featured_image_id" field.
  2680  func (m *PageMutation) ResetFeaturedImageID() {
  2681  	m.featured_image = nil
  2682  	delete(m.clearedFields, page.FieldFeaturedImageID)
  2683  }
  2684  
  2685  // ClearFeaturedImage clears the "featured_image" edge to the File entity.
  2686  func (m *PageMutation) ClearFeaturedImage() {
  2687  	m.clearedfeatured_image = true
  2688  }
  2689  
  2690  // FeaturedImageCleared reports if the "featured_image" edge to the File entity was cleared.
  2691  func (m *PageMutation) FeaturedImageCleared() bool {
  2692  	return m.FeaturedImageIDCleared() || m.clearedfeatured_image
  2693  }
  2694  
  2695  // FeaturedImageIDs returns the "featured_image" edge IDs in the mutation.
  2696  // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  2697  // FeaturedImageID instead. It exists only for internal usage by the builders.
  2698  func (m *PageMutation) FeaturedImageIDs() (ids []int) {
  2699  	if id := m.featured_image; id != nil {
  2700  		ids = append(ids, *id)
  2701  	}
  2702  	return
  2703  }
  2704  
  2705  // ResetFeaturedImage resets all changes to the "featured_image" edge.
  2706  func (m *PageMutation) ResetFeaturedImage() {
  2707  	m.featured_image = nil
  2708  	m.clearedfeatured_image = false
  2709  }
  2710  
  2711  // Where appends a list predicates to the PageMutation builder.
  2712  func (m *PageMutation) Where(ps ...predicate.Page) {
  2713  	m.predicates = append(m.predicates, ps...)
  2714  }
  2715  
  2716  // Op returns the operation name.
  2717  func (m *PageMutation) Op() Op {
  2718  	return m.op
  2719  }
  2720  
  2721  // Type returns the node type of this mutation (Page).
  2722  func (m *PageMutation) Type() string {
  2723  	return m.typ
  2724  }
  2725  
  2726  // Fields returns all fields that were changed during this mutation. Note that in
  2727  // order to get all numeric fields that were incremented/decremented, call
  2728  // AddedFields().
  2729  func (m *PageMutation) Fields() []string {
  2730  	fields := make([]string, 0, 9)
  2731  	if m.created_at != nil {
  2732  		fields = append(fields, page.FieldCreatedAt)
  2733  	}
  2734  	if m.updated_at != nil {
  2735  		fields = append(fields, page.FieldUpdatedAt)
  2736  	}
  2737  	if m.deleted_at != nil {
  2738  		fields = append(fields, page.FieldDeletedAt)
  2739  	}
  2740  	if m.name != nil {
  2741  		fields = append(fields, page.FieldName)
  2742  	}
  2743  	if m.slug != nil {
  2744  		fields = append(fields, page.FieldSlug)
  2745  	}
  2746  	if m.content != nil {
  2747  		fields = append(fields, page.FieldContent)
  2748  	}
  2749  	if m.content_html != nil {
  2750  		fields = append(fields, page.FieldContentHTML)
  2751  	}
  2752  	if m.draft != nil {
  2753  		fields = append(fields, page.FieldDraft)
  2754  	}
  2755  	if m.featured_image != nil {
  2756  		fields = append(fields, page.FieldFeaturedImageID)
  2757  	}
  2758  	return fields
  2759  }
  2760  
  2761  // Field returns the value of a field with the given name. The second boolean
  2762  // return value indicates that this field was not set, or was not defined in the
  2763  // schema.
  2764  func (m *PageMutation) Field(name string) (ent.Value, bool) {
  2765  	switch name {
  2766  	case page.FieldCreatedAt:
  2767  		return m.CreatedAt()
  2768  	case page.FieldUpdatedAt:
  2769  		return m.UpdatedAt()
  2770  	case page.FieldDeletedAt:
  2771  		return m.DeletedAt()
  2772  	case page.FieldName:
  2773  		return m.Name()
  2774  	case page.FieldSlug:
  2775  		return m.Slug()
  2776  	case page.FieldContent:
  2777  		return m.Content()
  2778  	case page.FieldContentHTML:
  2779  		return m.ContentHTML()
  2780  	case page.FieldDraft:
  2781  		return m.Draft()
  2782  	case page.FieldFeaturedImageID:
  2783  		return m.FeaturedImageID()
  2784  	}
  2785  	return nil, false
  2786  }
  2787  
  2788  // OldField returns the old value of the field from the database. An error is
  2789  // returned if the mutation operation is not UpdateOne, or the query to the
  2790  // database failed.
  2791  func (m *PageMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  2792  	switch name {
  2793  	case page.FieldCreatedAt:
  2794  		return m.OldCreatedAt(ctx)
  2795  	case page.FieldUpdatedAt:
  2796  		return m.OldUpdatedAt(ctx)
  2797  	case page.FieldDeletedAt:
  2798  		return m.OldDeletedAt(ctx)
  2799  	case page.FieldName:
  2800  		return m.OldName(ctx)
  2801  	case page.FieldSlug:
  2802  		return m.OldSlug(ctx)
  2803  	case page.FieldContent:
  2804  		return m.OldContent(ctx)
  2805  	case page.FieldContentHTML:
  2806  		return m.OldContentHTML(ctx)
  2807  	case page.FieldDraft:
  2808  		return m.OldDraft(ctx)
  2809  	case page.FieldFeaturedImageID:
  2810  		return m.OldFeaturedImageID(ctx)
  2811  	}
  2812  	return nil, fmt.Errorf("unknown Page field %s", name)
  2813  }
  2814  
  2815  // SetField sets the value of a field with the given name. It returns an error if
  2816  // the field is not defined in the schema, or if the type mismatched the field
  2817  // type.
  2818  func (m *PageMutation) SetField(name string, value ent.Value) error {
  2819  	switch name {
  2820  	case page.FieldCreatedAt:
  2821  		v, ok := value.(time.Time)
  2822  		if !ok {
  2823  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  2824  		}
  2825  		m.SetCreatedAt(v)
  2826  		return nil
  2827  	case page.FieldUpdatedAt:
  2828  		v, ok := value.(time.Time)
  2829  		if !ok {
  2830  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  2831  		}
  2832  		m.SetUpdatedAt(v)
  2833  		return nil
  2834  	case page.FieldDeletedAt:
  2835  		v, ok := value.(time.Time)
  2836  		if !ok {
  2837  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  2838  		}
  2839  		m.SetDeletedAt(v)
  2840  		return nil
  2841  	case page.FieldName:
  2842  		v, ok := value.(string)
  2843  		if !ok {
  2844  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  2845  		}
  2846  		m.SetName(v)
  2847  		return nil
  2848  	case page.FieldSlug:
  2849  		v, ok := value.(string)
  2850  		if !ok {
  2851  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  2852  		}
  2853  		m.SetSlug(v)
  2854  		return nil
  2855  	case page.FieldContent:
  2856  		v, ok := value.(string)
  2857  		if !ok {
  2858  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  2859  		}
  2860  		m.SetContent(v)
  2861  		return nil
  2862  	case page.FieldContentHTML:
  2863  		v, ok := value.(string)
  2864  		if !ok {
  2865  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  2866  		}
  2867  		m.SetContentHTML(v)
  2868  		return nil
  2869  	case page.FieldDraft:
  2870  		v, ok := value.(bool)
  2871  		if !ok {
  2872  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  2873  		}
  2874  		m.SetDraft(v)
  2875  		return nil
  2876  	case page.FieldFeaturedImageID:
  2877  		v, ok := value.(int)
  2878  		if !ok {
  2879  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  2880  		}
  2881  		m.SetFeaturedImageID(v)
  2882  		return nil
  2883  	}
  2884  	return fmt.Errorf("unknown Page field %s", name)
  2885  }
  2886  
  2887  // AddedFields returns all numeric fields that were incremented/decremented during
  2888  // this mutation.
  2889  func (m *PageMutation) AddedFields() []string {
  2890  	var fields []string
  2891  	return fields
  2892  }
  2893  
  2894  // AddedField returns the numeric value that was incremented/decremented on a field
  2895  // with the given name. The second boolean return value indicates that this field
  2896  // was not set, or was not defined in the schema.
  2897  func (m *PageMutation) AddedField(name string) (ent.Value, bool) {
  2898  	switch name {
  2899  	}
  2900  	return nil, false
  2901  }
  2902  
  2903  // AddField adds the value to the field with the given name. It returns an error if
  2904  // the field is not defined in the schema, or if the type mismatched the field
  2905  // type.
  2906  func (m *PageMutation) AddField(name string, value ent.Value) error {
  2907  	switch name {
  2908  	}
  2909  	return fmt.Errorf("unknown Page numeric field %s", name)
  2910  }
  2911  
  2912  // ClearedFields returns all nullable fields that were cleared during this
  2913  // mutation.
  2914  func (m *PageMutation) ClearedFields() []string {
  2915  	var fields []string
  2916  	if m.FieldCleared(page.FieldDeletedAt) {
  2917  		fields = append(fields, page.FieldDeletedAt)
  2918  	}
  2919  	if m.FieldCleared(page.FieldDraft) {
  2920  		fields = append(fields, page.FieldDraft)
  2921  	}
  2922  	if m.FieldCleared(page.FieldFeaturedImageID) {
  2923  		fields = append(fields, page.FieldFeaturedImageID)
  2924  	}
  2925  	return fields
  2926  }
  2927  
  2928  // FieldCleared returns a boolean indicating if a field with the given name was
  2929  // cleared in this mutation.
  2930  func (m *PageMutation) FieldCleared(name string) bool {
  2931  	_, ok := m.clearedFields[name]
  2932  	return ok
  2933  }
  2934  
  2935  // ClearField clears the value of the field with the given name. It returns an
  2936  // error if the field is not defined in the schema.
  2937  func (m *PageMutation) ClearField(name string) error {
  2938  	switch name {
  2939  	case page.FieldDeletedAt:
  2940  		m.ClearDeletedAt()
  2941  		return nil
  2942  	case page.FieldDraft:
  2943  		m.ClearDraft()
  2944  		return nil
  2945  	case page.FieldFeaturedImageID:
  2946  		m.ClearFeaturedImageID()
  2947  		return nil
  2948  	}
  2949  	return fmt.Errorf("unknown Page nullable field %s", name)
  2950  }
  2951  
  2952  // ResetField resets all changes in the mutation for the field with the given name.
  2953  // It returns an error if the field is not defined in the schema.
  2954  func (m *PageMutation) ResetField(name string) error {
  2955  	switch name {
  2956  	case page.FieldCreatedAt:
  2957  		m.ResetCreatedAt()
  2958  		return nil
  2959  	case page.FieldUpdatedAt:
  2960  		m.ResetUpdatedAt()
  2961  		return nil
  2962  	case page.FieldDeletedAt:
  2963  		m.ResetDeletedAt()
  2964  		return nil
  2965  	case page.FieldName:
  2966  		m.ResetName()
  2967  		return nil
  2968  	case page.FieldSlug:
  2969  		m.ResetSlug()
  2970  		return nil
  2971  	case page.FieldContent:
  2972  		m.ResetContent()
  2973  		return nil
  2974  	case page.FieldContentHTML:
  2975  		m.ResetContentHTML()
  2976  		return nil
  2977  	case page.FieldDraft:
  2978  		m.ResetDraft()
  2979  		return nil
  2980  	case page.FieldFeaturedImageID:
  2981  		m.ResetFeaturedImageID()
  2982  		return nil
  2983  	}
  2984  	return fmt.Errorf("unknown Page field %s", name)
  2985  }
  2986  
  2987  // AddedEdges returns all edge names that were set/added in this mutation.
  2988  func (m *PageMutation) AddedEdges() []string {
  2989  	edges := make([]string, 0, 1)
  2990  	if m.featured_image != nil {
  2991  		edges = append(edges, page.EdgeFeaturedImage)
  2992  	}
  2993  	return edges
  2994  }
  2995  
  2996  // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  2997  // name in this mutation.
  2998  func (m *PageMutation) AddedIDs(name string) []ent.Value {
  2999  	switch name {
  3000  	case page.EdgeFeaturedImage:
  3001  		if id := m.featured_image; id != nil {
  3002  			return []ent.Value{*id}
  3003  		}
  3004  	}
  3005  	return nil
  3006  }
  3007  
  3008  // RemovedEdges returns all edge names that were removed in this mutation.
  3009  func (m *PageMutation) RemovedEdges() []string {
  3010  	edges := make([]string, 0, 1)
  3011  	return edges
  3012  }
  3013  
  3014  // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  3015  // the given name in this mutation.
  3016  func (m *PageMutation) RemovedIDs(name string) []ent.Value {
  3017  	switch name {
  3018  	}
  3019  	return nil
  3020  }
  3021  
  3022  // ClearedEdges returns all edge names that were cleared in this mutation.
  3023  func (m *PageMutation) ClearedEdges() []string {
  3024  	edges := make([]string, 0, 1)
  3025  	if m.clearedfeatured_image {
  3026  		edges = append(edges, page.EdgeFeaturedImage)
  3027  	}
  3028  	return edges
  3029  }
  3030  
  3031  // EdgeCleared returns a boolean which indicates if the edge with the given name
  3032  // was cleared in this mutation.
  3033  func (m *PageMutation) EdgeCleared(name string) bool {
  3034  	switch name {
  3035  	case page.EdgeFeaturedImage:
  3036  		return m.clearedfeatured_image
  3037  	}
  3038  	return false
  3039  }
  3040  
  3041  // ClearEdge clears the value of the edge with the given name. It returns an error
  3042  // if that edge is not defined in the schema.
  3043  func (m *PageMutation) ClearEdge(name string) error {
  3044  	switch name {
  3045  	case page.EdgeFeaturedImage:
  3046  		m.ClearFeaturedImage()
  3047  		return nil
  3048  	}
  3049  	return fmt.Errorf("unknown Page unique edge %s", name)
  3050  }
  3051  
  3052  // ResetEdge resets all changes to the edge with the given name in this mutation.
  3053  // It returns an error if the edge is not defined in the schema.
  3054  func (m *PageMutation) ResetEdge(name string) error {
  3055  	switch name {
  3056  	case page.EdgeFeaturedImage:
  3057  		m.ResetFeaturedImage()
  3058  		return nil
  3059  	}
  3060  	return fmt.Errorf("unknown Page edge %s", name)
  3061  }
  3062  
  3063  // PermissionMutation represents an operation that mutates the Permission nodes in the graph.
  3064  type PermissionMutation struct {
  3065  	config
  3066  	op            Op
  3067  	typ           string
  3068  	id            *int
  3069  	created_at    *time.Time
  3070  	updated_at    *time.Time
  3071  	deleted_at    *time.Time
  3072  	action        *string
  3073  	value         *string
  3074  	clearedFields map[string]struct{}
  3075  	role          *int
  3076  	clearedrole   bool
  3077  	done          bool
  3078  	oldValue      func(context.Context) (*Permission, error)
  3079  	predicates    []predicate.Permission
  3080  }
  3081  
  3082  var _ ent.Mutation = (*PermissionMutation)(nil)
  3083  
  3084  // permissionOption allows management of the mutation configuration using functional options.
  3085  type permissionOption func(*PermissionMutation)
  3086  
  3087  // newPermissionMutation creates new mutation for the Permission entity.
  3088  func newPermissionMutation(c config, op Op, opts ...permissionOption) *PermissionMutation {
  3089  	m := &PermissionMutation{
  3090  		config:        c,
  3091  		op:            op,
  3092  		typ:           TypePermission,
  3093  		clearedFields: make(map[string]struct{}),
  3094  	}
  3095  	for _, opt := range opts {
  3096  		opt(m)
  3097  	}
  3098  	return m
  3099  }
  3100  
  3101  // withPermissionID sets the ID field of the mutation.
  3102  func withPermissionID(id int) permissionOption {
  3103  	return func(m *PermissionMutation) {
  3104  		var (
  3105  			err   error
  3106  			once  sync.Once
  3107  			value *Permission
  3108  		)
  3109  		m.oldValue = func(ctx context.Context) (*Permission, error) {
  3110  			once.Do(func() {
  3111  				if m.done {
  3112  					err = errors.New("querying old values post mutation is not allowed")
  3113  				} else {
  3114  					value, err = m.Client().Permission.Get(ctx, id)
  3115  				}
  3116  			})
  3117  			return value, err
  3118  		}
  3119  		m.id = &id
  3120  	}
  3121  }
  3122  
  3123  // withPermission sets the old Permission of the mutation.
  3124  func withPermission(node *Permission) permissionOption {
  3125  	return func(m *PermissionMutation) {
  3126  		m.oldValue = func(context.Context) (*Permission, error) {
  3127  			return node, nil
  3128  		}
  3129  		m.id = &node.ID
  3130  	}
  3131  }
  3132  
  3133  // Client returns a new `ent.Client` from the mutation. If the mutation was
  3134  // executed in a transaction (ent.Tx), a transactional client is returned.
  3135  func (m PermissionMutation) Client() *Client {
  3136  	client := &Client{config: m.config}
  3137  	client.init()
  3138  	return client
  3139  }
  3140  
  3141  // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  3142  // it returns an error otherwise.
  3143  func (m PermissionMutation) Tx() (*Tx, error) {
  3144  	if _, ok := m.driver.(*txDriver); !ok {
  3145  		return nil, errors.New("ent: mutation is not running in a transaction")
  3146  	}
  3147  	tx := &Tx{config: m.config}
  3148  	tx.init()
  3149  	return tx, nil
  3150  }
  3151  
  3152  // ID returns the ID value in the mutation. Note that the ID is only available
  3153  // if it was provided to the builder or after it was returned from the database.
  3154  func (m *PermissionMutation) ID() (id int, exists bool) {
  3155  	if m.id == nil {
  3156  		return
  3157  	}
  3158  	return *m.id, true
  3159  }
  3160  
  3161  // IDs queries the database and returns the entity ids that match the mutation's predicate.
  3162  // That means, if the mutation is applied within a transaction with an isolation level such
  3163  // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  3164  // or updated by the mutation.
  3165  func (m *PermissionMutation) IDs(ctx context.Context) ([]int, error) {
  3166  	switch {
  3167  	case m.op.Is(OpUpdateOne | OpDeleteOne):
  3168  		id, exists := m.ID()
  3169  		if exists {
  3170  			return []int{id}, nil
  3171  		}
  3172  		fallthrough
  3173  	case m.op.Is(OpUpdate | OpDelete):
  3174  		return m.Client().Permission.Query().Where(m.predicates...).IDs(ctx)
  3175  	default:
  3176  		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  3177  	}
  3178  }
  3179  
  3180  // SetCreatedAt sets the "created_at" field.
  3181  func (m *PermissionMutation) SetCreatedAt(t time.Time) {
  3182  	m.created_at = &t
  3183  }
  3184  
  3185  // CreatedAt returns the value of the "created_at" field in the mutation.
  3186  func (m *PermissionMutation) CreatedAt() (r time.Time, exists bool) {
  3187  	v := m.created_at
  3188  	if v == nil {
  3189  		return
  3190  	}
  3191  	return *v, true
  3192  }
  3193  
  3194  // OldCreatedAt returns the old "created_at" field's value of the Permission entity.
  3195  // If the Permission object wasn't provided to the builder, the object is fetched from the database.
  3196  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3197  func (m *PermissionMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  3198  	if !m.op.Is(OpUpdateOne) {
  3199  		return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  3200  	}
  3201  	if m.id == nil || m.oldValue == nil {
  3202  		return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  3203  	}
  3204  	oldValue, err := m.oldValue(ctx)
  3205  	if err != nil {
  3206  		return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  3207  	}
  3208  	return oldValue.CreatedAt, nil
  3209  }
  3210  
  3211  // ResetCreatedAt resets all changes to the "created_at" field.
  3212  func (m *PermissionMutation) ResetCreatedAt() {
  3213  	m.created_at = nil
  3214  }
  3215  
  3216  // SetUpdatedAt sets the "updated_at" field.
  3217  func (m *PermissionMutation) SetUpdatedAt(t time.Time) {
  3218  	m.updated_at = &t
  3219  }
  3220  
  3221  // UpdatedAt returns the value of the "updated_at" field in the mutation.
  3222  func (m *PermissionMutation) UpdatedAt() (r time.Time, exists bool) {
  3223  	v := m.updated_at
  3224  	if v == nil {
  3225  		return
  3226  	}
  3227  	return *v, true
  3228  }
  3229  
  3230  // OldUpdatedAt returns the old "updated_at" field's value of the Permission entity.
  3231  // If the Permission object wasn't provided to the builder, the object is fetched from the database.
  3232  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3233  func (m *PermissionMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  3234  	if !m.op.Is(OpUpdateOne) {
  3235  		return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  3236  	}
  3237  	if m.id == nil || m.oldValue == nil {
  3238  		return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  3239  	}
  3240  	oldValue, err := m.oldValue(ctx)
  3241  	if err != nil {
  3242  		return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  3243  	}
  3244  	return oldValue.UpdatedAt, nil
  3245  }
  3246  
  3247  // ResetUpdatedAt resets all changes to the "updated_at" field.
  3248  func (m *PermissionMutation) ResetUpdatedAt() {
  3249  	m.updated_at = nil
  3250  }
  3251  
  3252  // SetDeletedAt sets the "deleted_at" field.
  3253  func (m *PermissionMutation) SetDeletedAt(t time.Time) {
  3254  	m.deleted_at = &t
  3255  }
  3256  
  3257  // DeletedAt returns the value of the "deleted_at" field in the mutation.
  3258  func (m *PermissionMutation) DeletedAt() (r time.Time, exists bool) {
  3259  	v := m.deleted_at
  3260  	if v == nil {
  3261  		return
  3262  	}
  3263  	return *v, true
  3264  }
  3265  
  3266  // OldDeletedAt returns the old "deleted_at" field's value of the Permission entity.
  3267  // If the Permission object wasn't provided to the builder, the object is fetched from the database.
  3268  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3269  func (m *PermissionMutation) OldDeletedAt(ctx context.Context) (v time.Time, err error) {
  3270  	if !m.op.Is(OpUpdateOne) {
  3271  		return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
  3272  	}
  3273  	if m.id == nil || m.oldValue == nil {
  3274  		return v, errors.New("OldDeletedAt requires an ID field in the mutation")
  3275  	}
  3276  	oldValue, err := m.oldValue(ctx)
  3277  	if err != nil {
  3278  		return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
  3279  	}
  3280  	return oldValue.DeletedAt, nil
  3281  }
  3282  
  3283  // ClearDeletedAt clears the value of the "deleted_at" field.
  3284  func (m *PermissionMutation) ClearDeletedAt() {
  3285  	m.deleted_at = nil
  3286  	m.clearedFields[permission.FieldDeletedAt] = struct{}{}
  3287  }
  3288  
  3289  // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
  3290  func (m *PermissionMutation) DeletedAtCleared() bool {
  3291  	_, ok := m.clearedFields[permission.FieldDeletedAt]
  3292  	return ok
  3293  }
  3294  
  3295  // ResetDeletedAt resets all changes to the "deleted_at" field.
  3296  func (m *PermissionMutation) ResetDeletedAt() {
  3297  	m.deleted_at = nil
  3298  	delete(m.clearedFields, permission.FieldDeletedAt)
  3299  }
  3300  
  3301  // SetRoleID sets the "role_id" field.
  3302  func (m *PermissionMutation) SetRoleID(i int) {
  3303  	m.role = &i
  3304  }
  3305  
  3306  // RoleID returns the value of the "role_id" field in the mutation.
  3307  func (m *PermissionMutation) RoleID() (r int, exists bool) {
  3308  	v := m.role
  3309  	if v == nil {
  3310  		return
  3311  	}
  3312  	return *v, true
  3313  }
  3314  
  3315  // OldRoleID returns the old "role_id" field's value of the Permission entity.
  3316  // If the Permission object wasn't provided to the builder, the object is fetched from the database.
  3317  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3318  func (m *PermissionMutation) OldRoleID(ctx context.Context) (v int, err error) {
  3319  	if !m.op.Is(OpUpdateOne) {
  3320  		return v, errors.New("OldRoleID is only allowed on UpdateOne operations")
  3321  	}
  3322  	if m.id == nil || m.oldValue == nil {
  3323  		return v, errors.New("OldRoleID requires an ID field in the mutation")
  3324  	}
  3325  	oldValue, err := m.oldValue(ctx)
  3326  	if err != nil {
  3327  		return v, fmt.Errorf("querying old value for OldRoleID: %w", err)
  3328  	}
  3329  	return oldValue.RoleID, nil
  3330  }
  3331  
  3332  // ResetRoleID resets all changes to the "role_id" field.
  3333  func (m *PermissionMutation) ResetRoleID() {
  3334  	m.role = nil
  3335  }
  3336  
  3337  // SetAction sets the "action" field.
  3338  func (m *PermissionMutation) SetAction(s string) {
  3339  	m.action = &s
  3340  }
  3341  
  3342  // Action returns the value of the "action" field in the mutation.
  3343  func (m *PermissionMutation) Action() (r string, exists bool) {
  3344  	v := m.action
  3345  	if v == nil {
  3346  		return
  3347  	}
  3348  	return *v, true
  3349  }
  3350  
  3351  // OldAction returns the old "action" field's value of the Permission entity.
  3352  // If the Permission object wasn't provided to the builder, the object is fetched from the database.
  3353  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3354  func (m *PermissionMutation) OldAction(ctx context.Context) (v string, err error) {
  3355  	if !m.op.Is(OpUpdateOne) {
  3356  		return v, errors.New("OldAction is only allowed on UpdateOne operations")
  3357  	}
  3358  	if m.id == nil || m.oldValue == nil {
  3359  		return v, errors.New("OldAction requires an ID field in the mutation")
  3360  	}
  3361  	oldValue, err := m.oldValue(ctx)
  3362  	if err != nil {
  3363  		return v, fmt.Errorf("querying old value for OldAction: %w", err)
  3364  	}
  3365  	return oldValue.Action, nil
  3366  }
  3367  
  3368  // ResetAction resets all changes to the "action" field.
  3369  func (m *PermissionMutation) ResetAction() {
  3370  	m.action = nil
  3371  }
  3372  
  3373  // SetValue sets the "value" field.
  3374  func (m *PermissionMutation) SetValue(s string) {
  3375  	m.value = &s
  3376  }
  3377  
  3378  // Value returns the value of the "value" field in the mutation.
  3379  func (m *PermissionMutation) Value() (r string, exists bool) {
  3380  	v := m.value
  3381  	if v == nil {
  3382  		return
  3383  	}
  3384  	return *v, true
  3385  }
  3386  
  3387  // OldValue returns the old "value" field's value of the Permission entity.
  3388  // If the Permission object wasn't provided to the builder, the object is fetched from the database.
  3389  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3390  func (m *PermissionMutation) OldValue(ctx context.Context) (v string, err error) {
  3391  	if !m.op.Is(OpUpdateOne) {
  3392  		return v, errors.New("OldValue is only allowed on UpdateOne operations")
  3393  	}
  3394  	if m.id == nil || m.oldValue == nil {
  3395  		return v, errors.New("OldValue requires an ID field in the mutation")
  3396  	}
  3397  	oldValue, err := m.oldValue(ctx)
  3398  	if err != nil {
  3399  		return v, fmt.Errorf("querying old value for OldValue: %w", err)
  3400  	}
  3401  	return oldValue.Value, nil
  3402  }
  3403  
  3404  // ResetValue resets all changes to the "value" field.
  3405  func (m *PermissionMutation) ResetValue() {
  3406  	m.value = nil
  3407  }
  3408  
  3409  // ClearRole clears the "role" edge to the Role entity.
  3410  func (m *PermissionMutation) ClearRole() {
  3411  	m.clearedrole = true
  3412  }
  3413  
  3414  // RoleCleared reports if the "role" edge to the Role entity was cleared.
  3415  func (m *PermissionMutation) RoleCleared() bool {
  3416  	return m.clearedrole
  3417  }
  3418  
  3419  // RoleIDs returns the "role" edge IDs in the mutation.
  3420  // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  3421  // RoleID instead. It exists only for internal usage by the builders.
  3422  func (m *PermissionMutation) RoleIDs() (ids []int) {
  3423  	if id := m.role; id != nil {
  3424  		ids = append(ids, *id)
  3425  	}
  3426  	return
  3427  }
  3428  
  3429  // ResetRole resets all changes to the "role" edge.
  3430  func (m *PermissionMutation) ResetRole() {
  3431  	m.role = nil
  3432  	m.clearedrole = false
  3433  }
  3434  
  3435  // Where appends a list predicates to the PermissionMutation builder.
  3436  func (m *PermissionMutation) Where(ps ...predicate.Permission) {
  3437  	m.predicates = append(m.predicates, ps...)
  3438  }
  3439  
  3440  // Op returns the operation name.
  3441  func (m *PermissionMutation) Op() Op {
  3442  	return m.op
  3443  }
  3444  
  3445  // Type returns the node type of this mutation (Permission).
  3446  func (m *PermissionMutation) Type() string {
  3447  	return m.typ
  3448  }
  3449  
  3450  // Fields returns all fields that were changed during this mutation. Note that in
  3451  // order to get all numeric fields that were incremented/decremented, call
  3452  // AddedFields().
  3453  func (m *PermissionMutation) Fields() []string {
  3454  	fields := make([]string, 0, 6)
  3455  	if m.created_at != nil {
  3456  		fields = append(fields, permission.FieldCreatedAt)
  3457  	}
  3458  	if m.updated_at != nil {
  3459  		fields = append(fields, permission.FieldUpdatedAt)
  3460  	}
  3461  	if m.deleted_at != nil {
  3462  		fields = append(fields, permission.FieldDeletedAt)
  3463  	}
  3464  	if m.role != nil {
  3465  		fields = append(fields, permission.FieldRoleID)
  3466  	}
  3467  	if m.action != nil {
  3468  		fields = append(fields, permission.FieldAction)
  3469  	}
  3470  	if m.value != nil {
  3471  		fields = append(fields, permission.FieldValue)
  3472  	}
  3473  	return fields
  3474  }
  3475  
  3476  // Field returns the value of a field with the given name. The second boolean
  3477  // return value indicates that this field was not set, or was not defined in the
  3478  // schema.
  3479  func (m *PermissionMutation) Field(name string) (ent.Value, bool) {
  3480  	switch name {
  3481  	case permission.FieldCreatedAt:
  3482  		return m.CreatedAt()
  3483  	case permission.FieldUpdatedAt:
  3484  		return m.UpdatedAt()
  3485  	case permission.FieldDeletedAt:
  3486  		return m.DeletedAt()
  3487  	case permission.FieldRoleID:
  3488  		return m.RoleID()
  3489  	case permission.FieldAction:
  3490  		return m.Action()
  3491  	case permission.FieldValue:
  3492  		return m.Value()
  3493  	}
  3494  	return nil, false
  3495  }
  3496  
  3497  // OldField returns the old value of the field from the database. An error is
  3498  // returned if the mutation operation is not UpdateOne, or the query to the
  3499  // database failed.
  3500  func (m *PermissionMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  3501  	switch name {
  3502  	case permission.FieldCreatedAt:
  3503  		return m.OldCreatedAt(ctx)
  3504  	case permission.FieldUpdatedAt:
  3505  		return m.OldUpdatedAt(ctx)
  3506  	case permission.FieldDeletedAt:
  3507  		return m.OldDeletedAt(ctx)
  3508  	case permission.FieldRoleID:
  3509  		return m.OldRoleID(ctx)
  3510  	case permission.FieldAction:
  3511  		return m.OldAction(ctx)
  3512  	case permission.FieldValue:
  3513  		return m.OldValue(ctx)
  3514  	}
  3515  	return nil, fmt.Errorf("unknown Permission field %s", name)
  3516  }
  3517  
  3518  // SetField sets the value of a field with the given name. It returns an error if
  3519  // the field is not defined in the schema, or if the type mismatched the field
  3520  // type.
  3521  func (m *PermissionMutation) SetField(name string, value ent.Value) error {
  3522  	switch name {
  3523  	case permission.FieldCreatedAt:
  3524  		v, ok := value.(time.Time)
  3525  		if !ok {
  3526  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  3527  		}
  3528  		m.SetCreatedAt(v)
  3529  		return nil
  3530  	case permission.FieldUpdatedAt:
  3531  		v, ok := value.(time.Time)
  3532  		if !ok {
  3533  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  3534  		}
  3535  		m.SetUpdatedAt(v)
  3536  		return nil
  3537  	case permission.FieldDeletedAt:
  3538  		v, ok := value.(time.Time)
  3539  		if !ok {
  3540  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  3541  		}
  3542  		m.SetDeletedAt(v)
  3543  		return nil
  3544  	case permission.FieldRoleID:
  3545  		v, ok := value.(int)
  3546  		if !ok {
  3547  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  3548  		}
  3549  		m.SetRoleID(v)
  3550  		return nil
  3551  	case permission.FieldAction:
  3552  		v, ok := value.(string)
  3553  		if !ok {
  3554  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  3555  		}
  3556  		m.SetAction(v)
  3557  		return nil
  3558  	case permission.FieldValue:
  3559  		v, ok := value.(string)
  3560  		if !ok {
  3561  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  3562  		}
  3563  		m.SetValue(v)
  3564  		return nil
  3565  	}
  3566  	return fmt.Errorf("unknown Permission field %s", name)
  3567  }
  3568  
  3569  // AddedFields returns all numeric fields that were incremented/decremented during
  3570  // this mutation.
  3571  func (m *PermissionMutation) AddedFields() []string {
  3572  	var fields []string
  3573  	return fields
  3574  }
  3575  
  3576  // AddedField returns the numeric value that was incremented/decremented on a field
  3577  // with the given name. The second boolean return value indicates that this field
  3578  // was not set, or was not defined in the schema.
  3579  func (m *PermissionMutation) AddedField(name string) (ent.Value, bool) {
  3580  	switch name {
  3581  	}
  3582  	return nil, false
  3583  }
  3584  
  3585  // AddField adds the value to the field with the given name. It returns an error if
  3586  // the field is not defined in the schema, or if the type mismatched the field
  3587  // type.
  3588  func (m *PermissionMutation) AddField(name string, value ent.Value) error {
  3589  	switch name {
  3590  	}
  3591  	return fmt.Errorf("unknown Permission numeric field %s", name)
  3592  }
  3593  
  3594  // ClearedFields returns all nullable fields that were cleared during this
  3595  // mutation.
  3596  func (m *PermissionMutation) ClearedFields() []string {
  3597  	var fields []string
  3598  	if m.FieldCleared(permission.FieldDeletedAt) {
  3599  		fields = append(fields, permission.FieldDeletedAt)
  3600  	}
  3601  	return fields
  3602  }
  3603  
  3604  // FieldCleared returns a boolean indicating if a field with the given name was
  3605  // cleared in this mutation.
  3606  func (m *PermissionMutation) FieldCleared(name string) bool {
  3607  	_, ok := m.clearedFields[name]
  3608  	return ok
  3609  }
  3610  
  3611  // ClearField clears the value of the field with the given name. It returns an
  3612  // error if the field is not defined in the schema.
  3613  func (m *PermissionMutation) ClearField(name string) error {
  3614  	switch name {
  3615  	case permission.FieldDeletedAt:
  3616  		m.ClearDeletedAt()
  3617  		return nil
  3618  	}
  3619  	return fmt.Errorf("unknown Permission nullable field %s", name)
  3620  }
  3621  
  3622  // ResetField resets all changes in the mutation for the field with the given name.
  3623  // It returns an error if the field is not defined in the schema.
  3624  func (m *PermissionMutation) ResetField(name string) error {
  3625  	switch name {
  3626  	case permission.FieldCreatedAt:
  3627  		m.ResetCreatedAt()
  3628  		return nil
  3629  	case permission.FieldUpdatedAt:
  3630  		m.ResetUpdatedAt()
  3631  		return nil
  3632  	case permission.FieldDeletedAt:
  3633  		m.ResetDeletedAt()
  3634  		return nil
  3635  	case permission.FieldRoleID:
  3636  		m.ResetRoleID()
  3637  		return nil
  3638  	case permission.FieldAction:
  3639  		m.ResetAction()
  3640  		return nil
  3641  	case permission.FieldValue:
  3642  		m.ResetValue()
  3643  		return nil
  3644  	}
  3645  	return fmt.Errorf("unknown Permission field %s", name)
  3646  }
  3647  
  3648  // AddedEdges returns all edge names that were set/added in this mutation.
  3649  func (m *PermissionMutation) AddedEdges() []string {
  3650  	edges := make([]string, 0, 1)
  3651  	if m.role != nil {
  3652  		edges = append(edges, permission.EdgeRole)
  3653  	}
  3654  	return edges
  3655  }
  3656  
  3657  // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  3658  // name in this mutation.
  3659  func (m *PermissionMutation) AddedIDs(name string) []ent.Value {
  3660  	switch name {
  3661  	case permission.EdgeRole:
  3662  		if id := m.role; id != nil {
  3663  			return []ent.Value{*id}
  3664  		}
  3665  	}
  3666  	return nil
  3667  }
  3668  
  3669  // RemovedEdges returns all edge names that were removed in this mutation.
  3670  func (m *PermissionMutation) RemovedEdges() []string {
  3671  	edges := make([]string, 0, 1)
  3672  	return edges
  3673  }
  3674  
  3675  // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  3676  // the given name in this mutation.
  3677  func (m *PermissionMutation) RemovedIDs(name string) []ent.Value {
  3678  	switch name {
  3679  	}
  3680  	return nil
  3681  }
  3682  
  3683  // ClearedEdges returns all edge names that were cleared in this mutation.
  3684  func (m *PermissionMutation) ClearedEdges() []string {
  3685  	edges := make([]string, 0, 1)
  3686  	if m.clearedrole {
  3687  		edges = append(edges, permission.EdgeRole)
  3688  	}
  3689  	return edges
  3690  }
  3691  
  3692  // EdgeCleared returns a boolean which indicates if the edge with the given name
  3693  // was cleared in this mutation.
  3694  func (m *PermissionMutation) EdgeCleared(name string) bool {
  3695  	switch name {
  3696  	case permission.EdgeRole:
  3697  		return m.clearedrole
  3698  	}
  3699  	return false
  3700  }
  3701  
  3702  // ClearEdge clears the value of the edge with the given name. It returns an error
  3703  // if that edge is not defined in the schema.
  3704  func (m *PermissionMutation) ClearEdge(name string) error {
  3705  	switch name {
  3706  	case permission.EdgeRole:
  3707  		m.ClearRole()
  3708  		return nil
  3709  	}
  3710  	return fmt.Errorf("unknown Permission unique edge %s", name)
  3711  }
  3712  
  3713  // ResetEdge resets all changes to the edge with the given name in this mutation.
  3714  // It returns an error if the edge is not defined in the schema.
  3715  func (m *PermissionMutation) ResetEdge(name string) error {
  3716  	switch name {
  3717  	case permission.EdgeRole:
  3718  		m.ResetRole()
  3719  		return nil
  3720  	}
  3721  	return fmt.Errorf("unknown Permission edge %s", name)
  3722  }
  3723  
  3724  // PostMutation represents an operation that mutates the Post nodes in the graph.
  3725  type PostMutation struct {
  3726  	config
  3727  	op                    Op
  3728  	typ                   string
  3729  	id                    *int
  3730  	created_at            *time.Time
  3731  	updated_at            *time.Time
  3732  	deleted_at            *time.Time
  3733  	name                  *string
  3734  	slug                  *string
  3735  	description           *string
  3736  	content               *string
  3737  	content_html          *string
  3738  	view_count            *int64
  3739  	addview_count         *int64
  3740  	comment_count         *int64
  3741  	addcomment_count      *int64
  3742  	rating_count          *int64
  3743  	addrating_count       *int64
  3744  	rating_total          *int64
  3745  	addrating_total       *int64
  3746  	draft                 *bool
  3747  	approved              *bool
  3748  	clearedFields         map[string]struct{}
  3749  	user                  *int
  3750  	cleareduser           bool
  3751  	topics                map[int]struct{}
  3752  	removedtopics         map[int]struct{}
  3753  	clearedtopics         bool
  3754  	featured_image        *int
  3755  	clearedfeatured_image bool
  3756  	comments              map[int]struct{}
  3757  	removedcomments       map[int]struct{}
  3758  	clearedcomments       bool
  3759  	done                  bool
  3760  	oldValue              func(context.Context) (*Post, error)
  3761  	predicates            []predicate.Post
  3762  }
  3763  
  3764  var _ ent.Mutation = (*PostMutation)(nil)
  3765  
  3766  // postOption allows management of the mutation configuration using functional options.
  3767  type postOption func(*PostMutation)
  3768  
  3769  // newPostMutation creates new mutation for the Post entity.
  3770  func newPostMutation(c config, op Op, opts ...postOption) *PostMutation {
  3771  	m := &PostMutation{
  3772  		config:        c,
  3773  		op:            op,
  3774  		typ:           TypePost,
  3775  		clearedFields: make(map[string]struct{}),
  3776  	}
  3777  	for _, opt := range opts {
  3778  		opt(m)
  3779  	}
  3780  	return m
  3781  }
  3782  
  3783  // withPostID sets the ID field of the mutation.
  3784  func withPostID(id int) postOption {
  3785  	return func(m *PostMutation) {
  3786  		var (
  3787  			err   error
  3788  			once  sync.Once
  3789  			value *Post
  3790  		)
  3791  		m.oldValue = func(ctx context.Context) (*Post, error) {
  3792  			once.Do(func() {
  3793  				if m.done {
  3794  					err = errors.New("querying old values post mutation is not allowed")
  3795  				} else {
  3796  					value, err = m.Client().Post.Get(ctx, id)
  3797  				}
  3798  			})
  3799  			return value, err
  3800  		}
  3801  		m.id = &id
  3802  	}
  3803  }
  3804  
  3805  // withPost sets the old Post of the mutation.
  3806  func withPost(node *Post) postOption {
  3807  	return func(m *PostMutation) {
  3808  		m.oldValue = func(context.Context) (*Post, error) {
  3809  			return node, nil
  3810  		}
  3811  		m.id = &node.ID
  3812  	}
  3813  }
  3814  
  3815  // Client returns a new `ent.Client` from the mutation. If the mutation was
  3816  // executed in a transaction (ent.Tx), a transactional client is returned.
  3817  func (m PostMutation) Client() *Client {
  3818  	client := &Client{config: m.config}
  3819  	client.init()
  3820  	return client
  3821  }
  3822  
  3823  // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  3824  // it returns an error otherwise.
  3825  func (m PostMutation) Tx() (*Tx, error) {
  3826  	if _, ok := m.driver.(*txDriver); !ok {
  3827  		return nil, errors.New("ent: mutation is not running in a transaction")
  3828  	}
  3829  	tx := &Tx{config: m.config}
  3830  	tx.init()
  3831  	return tx, nil
  3832  }
  3833  
  3834  // ID returns the ID value in the mutation. Note that the ID is only available
  3835  // if it was provided to the builder or after it was returned from the database.
  3836  func (m *PostMutation) ID() (id int, exists bool) {
  3837  	if m.id == nil {
  3838  		return
  3839  	}
  3840  	return *m.id, true
  3841  }
  3842  
  3843  // IDs queries the database and returns the entity ids that match the mutation's predicate.
  3844  // That means, if the mutation is applied within a transaction with an isolation level such
  3845  // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  3846  // or updated by the mutation.
  3847  func (m *PostMutation) IDs(ctx context.Context) ([]int, error) {
  3848  	switch {
  3849  	case m.op.Is(OpUpdateOne | OpDeleteOne):
  3850  		id, exists := m.ID()
  3851  		if exists {
  3852  			return []int{id}, nil
  3853  		}
  3854  		fallthrough
  3855  	case m.op.Is(OpUpdate | OpDelete):
  3856  		return m.Client().Post.Query().Where(m.predicates...).IDs(ctx)
  3857  	default:
  3858  		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  3859  	}
  3860  }
  3861  
  3862  // SetCreatedAt sets the "created_at" field.
  3863  func (m *PostMutation) SetCreatedAt(t time.Time) {
  3864  	m.created_at = &t
  3865  }
  3866  
  3867  // CreatedAt returns the value of the "created_at" field in the mutation.
  3868  func (m *PostMutation) CreatedAt() (r time.Time, exists bool) {
  3869  	v := m.created_at
  3870  	if v == nil {
  3871  		return
  3872  	}
  3873  	return *v, true
  3874  }
  3875  
  3876  // OldCreatedAt returns the old "created_at" field's value of the Post entity.
  3877  // If the Post object wasn't provided to the builder, the object is fetched from the database.
  3878  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3879  func (m *PostMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  3880  	if !m.op.Is(OpUpdateOne) {
  3881  		return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  3882  	}
  3883  	if m.id == nil || m.oldValue == nil {
  3884  		return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  3885  	}
  3886  	oldValue, err := m.oldValue(ctx)
  3887  	if err != nil {
  3888  		return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  3889  	}
  3890  	return oldValue.CreatedAt, nil
  3891  }
  3892  
  3893  // ResetCreatedAt resets all changes to the "created_at" field.
  3894  func (m *PostMutation) ResetCreatedAt() {
  3895  	m.created_at = nil
  3896  }
  3897  
  3898  // SetUpdatedAt sets the "updated_at" field.
  3899  func (m *PostMutation) SetUpdatedAt(t time.Time) {
  3900  	m.updated_at = &t
  3901  }
  3902  
  3903  // UpdatedAt returns the value of the "updated_at" field in the mutation.
  3904  func (m *PostMutation) UpdatedAt() (r time.Time, exists bool) {
  3905  	v := m.updated_at
  3906  	if v == nil {
  3907  		return
  3908  	}
  3909  	return *v, true
  3910  }
  3911  
  3912  // OldUpdatedAt returns the old "updated_at" field's value of the Post entity.
  3913  // If the Post object wasn't provided to the builder, the object is fetched from the database.
  3914  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3915  func (m *PostMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  3916  	if !m.op.Is(OpUpdateOne) {
  3917  		return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  3918  	}
  3919  	if m.id == nil || m.oldValue == nil {
  3920  		return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  3921  	}
  3922  	oldValue, err := m.oldValue(ctx)
  3923  	if err != nil {
  3924  		return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  3925  	}
  3926  	return oldValue.UpdatedAt, nil
  3927  }
  3928  
  3929  // ResetUpdatedAt resets all changes to the "updated_at" field.
  3930  func (m *PostMutation) ResetUpdatedAt() {
  3931  	m.updated_at = nil
  3932  }
  3933  
  3934  // SetDeletedAt sets the "deleted_at" field.
  3935  func (m *PostMutation) SetDeletedAt(t time.Time) {
  3936  	m.deleted_at = &t
  3937  }
  3938  
  3939  // DeletedAt returns the value of the "deleted_at" field in the mutation.
  3940  func (m *PostMutation) DeletedAt() (r time.Time, exists bool) {
  3941  	v := m.deleted_at
  3942  	if v == nil {
  3943  		return
  3944  	}
  3945  	return *v, true
  3946  }
  3947  
  3948  // OldDeletedAt returns the old "deleted_at" field's value of the Post entity.
  3949  // If the Post object wasn't provided to the builder, the object is fetched from the database.
  3950  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  3951  func (m *PostMutation) OldDeletedAt(ctx context.Context) (v time.Time, err error) {
  3952  	if !m.op.Is(OpUpdateOne) {
  3953  		return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
  3954  	}
  3955  	if m.id == nil || m.oldValue == nil {
  3956  		return v, errors.New("OldDeletedAt requires an ID field in the mutation")
  3957  	}
  3958  	oldValue, err := m.oldValue(ctx)
  3959  	if err != nil {
  3960  		return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
  3961  	}
  3962  	return oldValue.DeletedAt, nil
  3963  }
  3964  
  3965  // ClearDeletedAt clears the value of the "deleted_at" field.
  3966  func (m *PostMutation) ClearDeletedAt() {
  3967  	m.deleted_at = nil
  3968  	m.clearedFields[post.FieldDeletedAt] = struct{}{}
  3969  }
  3970  
  3971  // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
  3972  func (m *PostMutation) DeletedAtCleared() bool {
  3973  	_, ok := m.clearedFields[post.FieldDeletedAt]
  3974  	return ok
  3975  }
  3976  
  3977  // ResetDeletedAt resets all changes to the "deleted_at" field.
  3978  func (m *PostMutation) ResetDeletedAt() {
  3979  	m.deleted_at = nil
  3980  	delete(m.clearedFields, post.FieldDeletedAt)
  3981  }
  3982  
  3983  // SetName sets the "name" field.
  3984  func (m *PostMutation) SetName(s string) {
  3985  	m.name = &s
  3986  }
  3987  
  3988  // Name returns the value of the "name" field in the mutation.
  3989  func (m *PostMutation) Name() (r string, exists bool) {
  3990  	v := m.name
  3991  	if v == nil {
  3992  		return
  3993  	}
  3994  	return *v, true
  3995  }
  3996  
  3997  // OldName returns the old "name" field's value of the Post entity.
  3998  // If the Post object wasn't provided to the builder, the object is fetched from the database.
  3999  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4000  func (m *PostMutation) OldName(ctx context.Context) (v string, err error) {
  4001  	if !m.op.Is(OpUpdateOne) {
  4002  		return v, errors.New("OldName is only allowed on UpdateOne operations")
  4003  	}
  4004  	if m.id == nil || m.oldValue == nil {
  4005  		return v, errors.New("OldName requires an ID field in the mutation")
  4006  	}
  4007  	oldValue, err := m.oldValue(ctx)
  4008  	if err != nil {
  4009  		return v, fmt.Errorf("querying old value for OldName: %w", err)
  4010  	}
  4011  	return oldValue.Name, nil
  4012  }
  4013  
  4014  // ResetName resets all changes to the "name" field.
  4015  func (m *PostMutation) ResetName() {
  4016  	m.name = nil
  4017  }
  4018  
  4019  // SetSlug sets the "slug" field.
  4020  func (m *PostMutation) SetSlug(s string) {
  4021  	m.slug = &s
  4022  }
  4023  
  4024  // Slug returns the value of the "slug" field in the mutation.
  4025  func (m *PostMutation) Slug() (r string, exists bool) {
  4026  	v := m.slug
  4027  	if v == nil {
  4028  		return
  4029  	}
  4030  	return *v, true
  4031  }
  4032  
  4033  // OldSlug returns the old "slug" field's value of the Post entity.
  4034  // If the Post object wasn't provided to the builder, the object is fetched from the database.
  4035  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4036  func (m *PostMutation) OldSlug(ctx context.Context) (v string, err error) {
  4037  	if !m.op.Is(OpUpdateOne) {
  4038  		return v, errors.New("OldSlug is only allowed on UpdateOne operations")
  4039  	}
  4040  	if m.id == nil || m.oldValue == nil {
  4041  		return v, errors.New("OldSlug requires an ID field in the mutation")
  4042  	}
  4043  	oldValue, err := m.oldValue(ctx)
  4044  	if err != nil {
  4045  		return v, fmt.Errorf("querying old value for OldSlug: %w", err)
  4046  	}
  4047  	return oldValue.Slug, nil
  4048  }
  4049  
  4050  // ResetSlug resets all changes to the "slug" field.
  4051  func (m *PostMutation) ResetSlug() {
  4052  	m.slug = nil
  4053  }
  4054  
  4055  // SetDescription sets the "description" field.
  4056  func (m *PostMutation) SetDescription(s string) {
  4057  	m.description = &s
  4058  }
  4059  
  4060  // Description returns the value of the "description" field in the mutation.
  4061  func (m *PostMutation) Description() (r string, exists bool) {
  4062  	v := m.description
  4063  	if v == nil {
  4064  		return
  4065  	}
  4066  	return *v, true
  4067  }
  4068  
  4069  // OldDescription returns the old "description" field's value of the Post entity.
  4070  // If the Post object wasn't provided to the builder, the object is fetched from the database.
  4071  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4072  func (m *PostMutation) OldDescription(ctx context.Context) (v string, err error) {
  4073  	if !m.op.Is(OpUpdateOne) {
  4074  		return v, errors.New("OldDescription is only allowed on UpdateOne operations")
  4075  	}
  4076  	if m.id == nil || m.oldValue == nil {
  4077  		return v, errors.New("OldDescription requires an ID field in the mutation")
  4078  	}
  4079  	oldValue, err := m.oldValue(ctx)
  4080  	if err != nil {
  4081  		return v, fmt.Errorf("querying old value for OldDescription: %w", err)
  4082  	}
  4083  	return oldValue.Description, nil
  4084  }
  4085  
  4086  // ClearDescription clears the value of the "description" field.
  4087  func (m *PostMutation) ClearDescription() {
  4088  	m.description = nil
  4089  	m.clearedFields[post.FieldDescription] = struct{}{}
  4090  }
  4091  
  4092  // DescriptionCleared returns if the "description" field was cleared in this mutation.
  4093  func (m *PostMutation) DescriptionCleared() bool {
  4094  	_, ok := m.clearedFields[post.FieldDescription]
  4095  	return ok
  4096  }
  4097  
  4098  // ResetDescription resets all changes to the "description" field.
  4099  func (m *PostMutation) ResetDescription() {
  4100  	m.description = nil
  4101  	delete(m.clearedFields, post.FieldDescription)
  4102  }
  4103  
  4104  // SetContent sets the "content" field.
  4105  func (m *PostMutation) SetContent(s string) {
  4106  	m.content = &s
  4107  }
  4108  
  4109  // Content returns the value of the "content" field in the mutation.
  4110  func (m *PostMutation) Content() (r string, exists bool) {
  4111  	v := m.content
  4112  	if v == nil {
  4113  		return
  4114  	}
  4115  	return *v, true
  4116  }
  4117  
  4118  // OldContent returns the old "content" field's value of the Post entity.
  4119  // If the Post object wasn't provided to the builder, the object is fetched from the database.
  4120  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4121  func (m *PostMutation) OldContent(ctx context.Context) (v string, err error) {
  4122  	if !m.op.Is(OpUpdateOne) {
  4123  		return v, errors.New("OldContent is only allowed on UpdateOne operations")
  4124  	}
  4125  	if m.id == nil || m.oldValue == nil {
  4126  		return v, errors.New("OldContent requires an ID field in the mutation")
  4127  	}
  4128  	oldValue, err := m.oldValue(ctx)
  4129  	if err != nil {
  4130  		return v, fmt.Errorf("querying old value for OldContent: %w", err)
  4131  	}
  4132  	return oldValue.Content, nil
  4133  }
  4134  
  4135  // ResetContent resets all changes to the "content" field.
  4136  func (m *PostMutation) ResetContent() {
  4137  	m.content = nil
  4138  }
  4139  
  4140  // SetContentHTML sets the "content_html" field.
  4141  func (m *PostMutation) SetContentHTML(s string) {
  4142  	m.content_html = &s
  4143  }
  4144  
  4145  // ContentHTML returns the value of the "content_html" field in the mutation.
  4146  func (m *PostMutation) ContentHTML() (r string, exists bool) {
  4147  	v := m.content_html
  4148  	if v == nil {
  4149  		return
  4150  	}
  4151  	return *v, true
  4152  }
  4153  
  4154  // OldContentHTML returns the old "content_html" field's value of the Post entity.
  4155  // If the Post object wasn't provided to the builder, the object is fetched from the database.
  4156  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4157  func (m *PostMutation) OldContentHTML(ctx context.Context) (v string, err error) {
  4158  	if !m.op.Is(OpUpdateOne) {
  4159  		return v, errors.New("OldContentHTML is only allowed on UpdateOne operations")
  4160  	}
  4161  	if m.id == nil || m.oldValue == nil {
  4162  		return v, errors.New("OldContentHTML requires an ID field in the mutation")
  4163  	}
  4164  	oldValue, err := m.oldValue(ctx)
  4165  	if err != nil {
  4166  		return v, fmt.Errorf("querying old value for OldContentHTML: %w", err)
  4167  	}
  4168  	return oldValue.ContentHTML, nil
  4169  }
  4170  
  4171  // ResetContentHTML resets all changes to the "content_html" field.
  4172  func (m *PostMutation) ResetContentHTML() {
  4173  	m.content_html = nil
  4174  }
  4175  
  4176  // SetViewCount sets the "view_count" field.
  4177  func (m *PostMutation) SetViewCount(i int64) {
  4178  	m.view_count = &i
  4179  	m.addview_count = nil
  4180  }
  4181  
  4182  // ViewCount returns the value of the "view_count" field in the mutation.
  4183  func (m *PostMutation) ViewCount() (r int64, exists bool) {
  4184  	v := m.view_count
  4185  	if v == nil {
  4186  		return
  4187  	}
  4188  	return *v, true
  4189  }
  4190  
  4191  // OldViewCount returns the old "view_count" field's value of the Post entity.
  4192  // If the Post object wasn't provided to the builder, the object is fetched from the database.
  4193  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4194  func (m *PostMutation) OldViewCount(ctx context.Context) (v int64, err error) {
  4195  	if !m.op.Is(OpUpdateOne) {
  4196  		return v, errors.New("OldViewCount is only allowed on UpdateOne operations")
  4197  	}
  4198  	if m.id == nil || m.oldValue == nil {
  4199  		return v, errors.New("OldViewCount requires an ID field in the mutation")
  4200  	}
  4201  	oldValue, err := m.oldValue(ctx)
  4202  	if err != nil {
  4203  		return v, fmt.Errorf("querying old value for OldViewCount: %w", err)
  4204  	}
  4205  	return oldValue.ViewCount, nil
  4206  }
  4207  
  4208  // AddViewCount adds i to the "view_count" field.
  4209  func (m *PostMutation) AddViewCount(i int64) {
  4210  	if m.addview_count != nil {
  4211  		*m.addview_count += i
  4212  	} else {
  4213  		m.addview_count = &i
  4214  	}
  4215  }
  4216  
  4217  // AddedViewCount returns the value that was added to the "view_count" field in this mutation.
  4218  func (m *PostMutation) AddedViewCount() (r int64, exists bool) {
  4219  	v := m.addview_count
  4220  	if v == nil {
  4221  		return
  4222  	}
  4223  	return *v, true
  4224  }
  4225  
  4226  // ResetViewCount resets all changes to the "view_count" field.
  4227  func (m *PostMutation) ResetViewCount() {
  4228  	m.view_count = nil
  4229  	m.addview_count = nil
  4230  }
  4231  
  4232  // SetCommentCount sets the "comment_count" field.
  4233  func (m *PostMutation) SetCommentCount(i int64) {
  4234  	m.comment_count = &i
  4235  	m.addcomment_count = nil
  4236  }
  4237  
  4238  // CommentCount returns the value of the "comment_count" field in the mutation.
  4239  func (m *PostMutation) CommentCount() (r int64, exists bool) {
  4240  	v := m.comment_count
  4241  	if v == nil {
  4242  		return
  4243  	}
  4244  	return *v, true
  4245  }
  4246  
  4247  // OldCommentCount returns the old "comment_count" field's value of the Post entity.
  4248  // If the Post object wasn't provided to the builder, the object is fetched from the database.
  4249  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4250  func (m *PostMutation) OldCommentCount(ctx context.Context) (v int64, err error) {
  4251  	if !m.op.Is(OpUpdateOne) {
  4252  		return v, errors.New("OldCommentCount is only allowed on UpdateOne operations")
  4253  	}
  4254  	if m.id == nil || m.oldValue == nil {
  4255  		return v, errors.New("OldCommentCount requires an ID field in the mutation")
  4256  	}
  4257  	oldValue, err := m.oldValue(ctx)
  4258  	if err != nil {
  4259  		return v, fmt.Errorf("querying old value for OldCommentCount: %w", err)
  4260  	}
  4261  	return oldValue.CommentCount, nil
  4262  }
  4263  
  4264  // AddCommentCount adds i to the "comment_count" field.
  4265  func (m *PostMutation) AddCommentCount(i int64) {
  4266  	if m.addcomment_count != nil {
  4267  		*m.addcomment_count += i
  4268  	} else {
  4269  		m.addcomment_count = &i
  4270  	}
  4271  }
  4272  
  4273  // AddedCommentCount returns the value that was added to the "comment_count" field in this mutation.
  4274  func (m *PostMutation) AddedCommentCount() (r int64, exists bool) {
  4275  	v := m.addcomment_count
  4276  	if v == nil {
  4277  		return
  4278  	}
  4279  	return *v, true
  4280  }
  4281  
  4282  // ResetCommentCount resets all changes to the "comment_count" field.
  4283  func (m *PostMutation) ResetCommentCount() {
  4284  	m.comment_count = nil
  4285  	m.addcomment_count = nil
  4286  }
  4287  
  4288  // SetRatingCount sets the "rating_count" field.
  4289  func (m *PostMutation) SetRatingCount(i int64) {
  4290  	m.rating_count = &i
  4291  	m.addrating_count = nil
  4292  }
  4293  
  4294  // RatingCount returns the value of the "rating_count" field in the mutation.
  4295  func (m *PostMutation) RatingCount() (r int64, exists bool) {
  4296  	v := m.rating_count
  4297  	if v == nil {
  4298  		return
  4299  	}
  4300  	return *v, true
  4301  }
  4302  
  4303  // OldRatingCount returns the old "rating_count" field's value of the Post entity.
  4304  // If the Post object wasn't provided to the builder, the object is fetched from the database.
  4305  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4306  func (m *PostMutation) OldRatingCount(ctx context.Context) (v int64, err error) {
  4307  	if !m.op.Is(OpUpdateOne) {
  4308  		return v, errors.New("OldRatingCount is only allowed on UpdateOne operations")
  4309  	}
  4310  	if m.id == nil || m.oldValue == nil {
  4311  		return v, errors.New("OldRatingCount requires an ID field in the mutation")
  4312  	}
  4313  	oldValue, err := m.oldValue(ctx)
  4314  	if err != nil {
  4315  		return v, fmt.Errorf("querying old value for OldRatingCount: %w", err)
  4316  	}
  4317  	return oldValue.RatingCount, nil
  4318  }
  4319  
  4320  // AddRatingCount adds i to the "rating_count" field.
  4321  func (m *PostMutation) AddRatingCount(i int64) {
  4322  	if m.addrating_count != nil {
  4323  		*m.addrating_count += i
  4324  	} else {
  4325  		m.addrating_count = &i
  4326  	}
  4327  }
  4328  
  4329  // AddedRatingCount returns the value that was added to the "rating_count" field in this mutation.
  4330  func (m *PostMutation) AddedRatingCount() (r int64, exists bool) {
  4331  	v := m.addrating_count
  4332  	if v == nil {
  4333  		return
  4334  	}
  4335  	return *v, true
  4336  }
  4337  
  4338  // ClearRatingCount clears the value of the "rating_count" field.
  4339  func (m *PostMutation) ClearRatingCount() {
  4340  	m.rating_count = nil
  4341  	m.addrating_count = nil
  4342  	m.clearedFields[post.FieldRatingCount] = struct{}{}
  4343  }
  4344  
  4345  // RatingCountCleared returns if the "rating_count" field was cleared in this mutation.
  4346  func (m *PostMutation) RatingCountCleared() bool {
  4347  	_, ok := m.clearedFields[post.FieldRatingCount]
  4348  	return ok
  4349  }
  4350  
  4351  // ResetRatingCount resets all changes to the "rating_count" field.
  4352  func (m *PostMutation) ResetRatingCount() {
  4353  	m.rating_count = nil
  4354  	m.addrating_count = nil
  4355  	delete(m.clearedFields, post.FieldRatingCount)
  4356  }
  4357  
  4358  // SetRatingTotal sets the "rating_total" field.
  4359  func (m *PostMutation) SetRatingTotal(i int64) {
  4360  	m.rating_total = &i
  4361  	m.addrating_total = nil
  4362  }
  4363  
  4364  // RatingTotal returns the value of the "rating_total" field in the mutation.
  4365  func (m *PostMutation) RatingTotal() (r int64, exists bool) {
  4366  	v := m.rating_total
  4367  	if v == nil {
  4368  		return
  4369  	}
  4370  	return *v, true
  4371  }
  4372  
  4373  // OldRatingTotal returns the old "rating_total" field's value of the Post entity.
  4374  // If the Post object wasn't provided to the builder, the object is fetched from the database.
  4375  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4376  func (m *PostMutation) OldRatingTotal(ctx context.Context) (v int64, err error) {
  4377  	if !m.op.Is(OpUpdateOne) {
  4378  		return v, errors.New("OldRatingTotal is only allowed on UpdateOne operations")
  4379  	}
  4380  	if m.id == nil || m.oldValue == nil {
  4381  		return v, errors.New("OldRatingTotal requires an ID field in the mutation")
  4382  	}
  4383  	oldValue, err := m.oldValue(ctx)
  4384  	if err != nil {
  4385  		return v, fmt.Errorf("querying old value for OldRatingTotal: %w", err)
  4386  	}
  4387  	return oldValue.RatingTotal, nil
  4388  }
  4389  
  4390  // AddRatingTotal adds i to the "rating_total" field.
  4391  func (m *PostMutation) AddRatingTotal(i int64) {
  4392  	if m.addrating_total != nil {
  4393  		*m.addrating_total += i
  4394  	} else {
  4395  		m.addrating_total = &i
  4396  	}
  4397  }
  4398  
  4399  // AddedRatingTotal returns the value that was added to the "rating_total" field in this mutation.
  4400  func (m *PostMutation) AddedRatingTotal() (r int64, exists bool) {
  4401  	v := m.addrating_total
  4402  	if v == nil {
  4403  		return
  4404  	}
  4405  	return *v, true
  4406  }
  4407  
  4408  // ClearRatingTotal clears the value of the "rating_total" field.
  4409  func (m *PostMutation) ClearRatingTotal() {
  4410  	m.rating_total = nil
  4411  	m.addrating_total = nil
  4412  	m.clearedFields[post.FieldRatingTotal] = struct{}{}
  4413  }
  4414  
  4415  // RatingTotalCleared returns if the "rating_total" field was cleared in this mutation.
  4416  func (m *PostMutation) RatingTotalCleared() bool {
  4417  	_, ok := m.clearedFields[post.FieldRatingTotal]
  4418  	return ok
  4419  }
  4420  
  4421  // ResetRatingTotal resets all changes to the "rating_total" field.
  4422  func (m *PostMutation) ResetRatingTotal() {
  4423  	m.rating_total = nil
  4424  	m.addrating_total = nil
  4425  	delete(m.clearedFields, post.FieldRatingTotal)
  4426  }
  4427  
  4428  // SetDraft sets the "draft" field.
  4429  func (m *PostMutation) SetDraft(b bool) {
  4430  	m.draft = &b
  4431  }
  4432  
  4433  // Draft returns the value of the "draft" field in the mutation.
  4434  func (m *PostMutation) Draft() (r bool, exists bool) {
  4435  	v := m.draft
  4436  	if v == nil {
  4437  		return
  4438  	}
  4439  	return *v, true
  4440  }
  4441  
  4442  // OldDraft returns the old "draft" field's value of the Post entity.
  4443  // If the Post object wasn't provided to the builder, the object is fetched from the database.
  4444  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4445  func (m *PostMutation) OldDraft(ctx context.Context) (v bool, err error) {
  4446  	if !m.op.Is(OpUpdateOne) {
  4447  		return v, errors.New("OldDraft is only allowed on UpdateOne operations")
  4448  	}
  4449  	if m.id == nil || m.oldValue == nil {
  4450  		return v, errors.New("OldDraft requires an ID field in the mutation")
  4451  	}
  4452  	oldValue, err := m.oldValue(ctx)
  4453  	if err != nil {
  4454  		return v, fmt.Errorf("querying old value for OldDraft: %w", err)
  4455  	}
  4456  	return oldValue.Draft, nil
  4457  }
  4458  
  4459  // ClearDraft clears the value of the "draft" field.
  4460  func (m *PostMutation) ClearDraft() {
  4461  	m.draft = nil
  4462  	m.clearedFields[post.FieldDraft] = struct{}{}
  4463  }
  4464  
  4465  // DraftCleared returns if the "draft" field was cleared in this mutation.
  4466  func (m *PostMutation) DraftCleared() bool {
  4467  	_, ok := m.clearedFields[post.FieldDraft]
  4468  	return ok
  4469  }
  4470  
  4471  // ResetDraft resets all changes to the "draft" field.
  4472  func (m *PostMutation) ResetDraft() {
  4473  	m.draft = nil
  4474  	delete(m.clearedFields, post.FieldDraft)
  4475  }
  4476  
  4477  // SetApproved sets the "approved" field.
  4478  func (m *PostMutation) SetApproved(b bool) {
  4479  	m.approved = &b
  4480  }
  4481  
  4482  // Approved returns the value of the "approved" field in the mutation.
  4483  func (m *PostMutation) Approved() (r bool, exists bool) {
  4484  	v := m.approved
  4485  	if v == nil {
  4486  		return
  4487  	}
  4488  	return *v, true
  4489  }
  4490  
  4491  // OldApproved returns the old "approved" field's value of the Post entity.
  4492  // If the Post object wasn't provided to the builder, the object is fetched from the database.
  4493  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4494  func (m *PostMutation) OldApproved(ctx context.Context) (v bool, err error) {
  4495  	if !m.op.Is(OpUpdateOne) {
  4496  		return v, errors.New("OldApproved is only allowed on UpdateOne operations")
  4497  	}
  4498  	if m.id == nil || m.oldValue == nil {
  4499  		return v, errors.New("OldApproved requires an ID field in the mutation")
  4500  	}
  4501  	oldValue, err := m.oldValue(ctx)
  4502  	if err != nil {
  4503  		return v, fmt.Errorf("querying old value for OldApproved: %w", err)
  4504  	}
  4505  	return oldValue.Approved, nil
  4506  }
  4507  
  4508  // ClearApproved clears the value of the "approved" field.
  4509  func (m *PostMutation) ClearApproved() {
  4510  	m.approved = nil
  4511  	m.clearedFields[post.FieldApproved] = struct{}{}
  4512  }
  4513  
  4514  // ApprovedCleared returns if the "approved" field was cleared in this mutation.
  4515  func (m *PostMutation) ApprovedCleared() bool {
  4516  	_, ok := m.clearedFields[post.FieldApproved]
  4517  	return ok
  4518  }
  4519  
  4520  // ResetApproved resets all changes to the "approved" field.
  4521  func (m *PostMutation) ResetApproved() {
  4522  	m.approved = nil
  4523  	delete(m.clearedFields, post.FieldApproved)
  4524  }
  4525  
  4526  // SetFeaturedImageID sets the "featured_image_id" field.
  4527  func (m *PostMutation) SetFeaturedImageID(i int) {
  4528  	m.featured_image = &i
  4529  }
  4530  
  4531  // FeaturedImageID returns the value of the "featured_image_id" field in the mutation.
  4532  func (m *PostMutation) FeaturedImageID() (r int, exists bool) {
  4533  	v := m.featured_image
  4534  	if v == nil {
  4535  		return
  4536  	}
  4537  	return *v, true
  4538  }
  4539  
  4540  // OldFeaturedImageID returns the old "featured_image_id" field's value of the Post entity.
  4541  // If the Post object wasn't provided to the builder, the object is fetched from the database.
  4542  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4543  func (m *PostMutation) OldFeaturedImageID(ctx context.Context) (v int, err error) {
  4544  	if !m.op.Is(OpUpdateOne) {
  4545  		return v, errors.New("OldFeaturedImageID is only allowed on UpdateOne operations")
  4546  	}
  4547  	if m.id == nil || m.oldValue == nil {
  4548  		return v, errors.New("OldFeaturedImageID requires an ID field in the mutation")
  4549  	}
  4550  	oldValue, err := m.oldValue(ctx)
  4551  	if err != nil {
  4552  		return v, fmt.Errorf("querying old value for OldFeaturedImageID: %w", err)
  4553  	}
  4554  	return oldValue.FeaturedImageID, nil
  4555  }
  4556  
  4557  // ClearFeaturedImageID clears the value of the "featured_image_id" field.
  4558  func (m *PostMutation) ClearFeaturedImageID() {
  4559  	m.featured_image = nil
  4560  	m.clearedFields[post.FieldFeaturedImageID] = struct{}{}
  4561  }
  4562  
  4563  // FeaturedImageIDCleared returns if the "featured_image_id" field was cleared in this mutation.
  4564  func (m *PostMutation) FeaturedImageIDCleared() bool {
  4565  	_, ok := m.clearedFields[post.FieldFeaturedImageID]
  4566  	return ok
  4567  }
  4568  
  4569  // ResetFeaturedImageID resets all changes to the "featured_image_id" field.
  4570  func (m *PostMutation) ResetFeaturedImageID() {
  4571  	m.featured_image = nil
  4572  	delete(m.clearedFields, post.FieldFeaturedImageID)
  4573  }
  4574  
  4575  // SetUserID sets the "user_id" field.
  4576  func (m *PostMutation) SetUserID(i int) {
  4577  	m.user = &i
  4578  }
  4579  
  4580  // UserID returns the value of the "user_id" field in the mutation.
  4581  func (m *PostMutation) UserID() (r int, exists bool) {
  4582  	v := m.user
  4583  	if v == nil {
  4584  		return
  4585  	}
  4586  	return *v, true
  4587  }
  4588  
  4589  // OldUserID returns the old "user_id" field's value of the Post entity.
  4590  // If the Post object wasn't provided to the builder, the object is fetched from the database.
  4591  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  4592  func (m *PostMutation) OldUserID(ctx context.Context) (v int, err error) {
  4593  	if !m.op.Is(OpUpdateOne) {
  4594  		return v, errors.New("OldUserID is only allowed on UpdateOne operations")
  4595  	}
  4596  	if m.id == nil || m.oldValue == nil {
  4597  		return v, errors.New("OldUserID requires an ID field in the mutation")
  4598  	}
  4599  	oldValue, err := m.oldValue(ctx)
  4600  	if err != nil {
  4601  		return v, fmt.Errorf("querying old value for OldUserID: %w", err)
  4602  	}
  4603  	return oldValue.UserID, nil
  4604  }
  4605  
  4606  // ClearUserID clears the value of the "user_id" field.
  4607  func (m *PostMutation) ClearUserID() {
  4608  	m.user = nil
  4609  	m.clearedFields[post.FieldUserID] = struct{}{}
  4610  }
  4611  
  4612  // UserIDCleared returns if the "user_id" field was cleared in this mutation.
  4613  func (m *PostMutation) UserIDCleared() bool {
  4614  	_, ok := m.clearedFields[post.FieldUserID]
  4615  	return ok
  4616  }
  4617  
  4618  // ResetUserID resets all changes to the "user_id" field.
  4619  func (m *PostMutation) ResetUserID() {
  4620  	m.user = nil
  4621  	delete(m.clearedFields, post.FieldUserID)
  4622  }
  4623  
  4624  // ClearUser clears the "user" edge to the User entity.
  4625  func (m *PostMutation) ClearUser() {
  4626  	m.cleareduser = true
  4627  }
  4628  
  4629  // UserCleared reports if the "user" edge to the User entity was cleared.
  4630  func (m *PostMutation) UserCleared() bool {
  4631  	return m.UserIDCleared() || m.cleareduser
  4632  }
  4633  
  4634  // UserIDs returns the "user" edge IDs in the mutation.
  4635  // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  4636  // UserID instead. It exists only for internal usage by the builders.
  4637  func (m *PostMutation) UserIDs() (ids []int) {
  4638  	if id := m.user; id != nil {
  4639  		ids = append(ids, *id)
  4640  	}
  4641  	return
  4642  }
  4643  
  4644  // ResetUser resets all changes to the "user" edge.
  4645  func (m *PostMutation) ResetUser() {
  4646  	m.user = nil
  4647  	m.cleareduser = false
  4648  }
  4649  
  4650  // AddTopicIDs adds the "topics" edge to the Topic entity by ids.
  4651  func (m *PostMutation) AddTopicIDs(ids ...int) {
  4652  	if m.topics == nil {
  4653  		m.topics = make(map[int]struct{})
  4654  	}
  4655  	for i := range ids {
  4656  		m.topics[ids[i]] = struct{}{}
  4657  	}
  4658  }
  4659  
  4660  // ClearTopics clears the "topics" edge to the Topic entity.
  4661  func (m *PostMutation) ClearTopics() {
  4662  	m.clearedtopics = true
  4663  }
  4664  
  4665  // TopicsCleared reports if the "topics" edge to the Topic entity was cleared.
  4666  func (m *PostMutation) TopicsCleared() bool {
  4667  	return m.clearedtopics
  4668  }
  4669  
  4670  // RemoveTopicIDs removes the "topics" edge to the Topic entity by IDs.
  4671  func (m *PostMutation) RemoveTopicIDs(ids ...int) {
  4672  	if m.removedtopics == nil {
  4673  		m.removedtopics = make(map[int]struct{})
  4674  	}
  4675  	for i := range ids {
  4676  		delete(m.topics, ids[i])
  4677  		m.removedtopics[ids[i]] = struct{}{}
  4678  	}
  4679  }
  4680  
  4681  // RemovedTopics returns the removed IDs of the "topics" edge to the Topic entity.
  4682  func (m *PostMutation) RemovedTopicsIDs() (ids []int) {
  4683  	for id := range m.removedtopics {
  4684  		ids = append(ids, id)
  4685  	}
  4686  	return
  4687  }
  4688  
  4689  // TopicsIDs returns the "topics" edge IDs in the mutation.
  4690  func (m *PostMutation) TopicsIDs() (ids []int) {
  4691  	for id := range m.topics {
  4692  		ids = append(ids, id)
  4693  	}
  4694  	return
  4695  }
  4696  
  4697  // ResetTopics resets all changes to the "topics" edge.
  4698  func (m *PostMutation) ResetTopics() {
  4699  	m.topics = nil
  4700  	m.clearedtopics = false
  4701  	m.removedtopics = nil
  4702  }
  4703  
  4704  // ClearFeaturedImage clears the "featured_image" edge to the File entity.
  4705  func (m *PostMutation) ClearFeaturedImage() {
  4706  	m.clearedfeatured_image = true
  4707  }
  4708  
  4709  // FeaturedImageCleared reports if the "featured_image" edge to the File entity was cleared.
  4710  func (m *PostMutation) FeaturedImageCleared() bool {
  4711  	return m.FeaturedImageIDCleared() || m.clearedfeatured_image
  4712  }
  4713  
  4714  // FeaturedImageIDs returns the "featured_image" edge IDs in the mutation.
  4715  // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  4716  // FeaturedImageID instead. It exists only for internal usage by the builders.
  4717  func (m *PostMutation) FeaturedImageIDs() (ids []int) {
  4718  	if id := m.featured_image; id != nil {
  4719  		ids = append(ids, *id)
  4720  	}
  4721  	return
  4722  }
  4723  
  4724  // ResetFeaturedImage resets all changes to the "featured_image" edge.
  4725  func (m *PostMutation) ResetFeaturedImage() {
  4726  	m.featured_image = nil
  4727  	m.clearedfeatured_image = false
  4728  }
  4729  
  4730  // AddCommentIDs adds the "comments" edge to the Comment entity by ids.
  4731  func (m *PostMutation) AddCommentIDs(ids ...int) {
  4732  	if m.comments == nil {
  4733  		m.comments = make(map[int]struct{})
  4734  	}
  4735  	for i := range ids {
  4736  		m.comments[ids[i]] = struct{}{}
  4737  	}
  4738  }
  4739  
  4740  // ClearComments clears the "comments" edge to the Comment entity.
  4741  func (m *PostMutation) ClearComments() {
  4742  	m.clearedcomments = true
  4743  }
  4744  
  4745  // CommentsCleared reports if the "comments" edge to the Comment entity was cleared.
  4746  func (m *PostMutation) CommentsCleared() bool {
  4747  	return m.clearedcomments
  4748  }
  4749  
  4750  // RemoveCommentIDs removes the "comments" edge to the Comment entity by IDs.
  4751  func (m *PostMutation) RemoveCommentIDs(ids ...int) {
  4752  	if m.removedcomments == nil {
  4753  		m.removedcomments = make(map[int]struct{})
  4754  	}
  4755  	for i := range ids {
  4756  		delete(m.comments, ids[i])
  4757  		m.removedcomments[ids[i]] = struct{}{}
  4758  	}
  4759  }
  4760  
  4761  // RemovedComments returns the removed IDs of the "comments" edge to the Comment entity.
  4762  func (m *PostMutation) RemovedCommentsIDs() (ids []int) {
  4763  	for id := range m.removedcomments {
  4764  		ids = append(ids, id)
  4765  	}
  4766  	return
  4767  }
  4768  
  4769  // CommentsIDs returns the "comments" edge IDs in the mutation.
  4770  func (m *PostMutation) CommentsIDs() (ids []int) {
  4771  	for id := range m.comments {
  4772  		ids = append(ids, id)
  4773  	}
  4774  	return
  4775  }
  4776  
  4777  // ResetComments resets all changes to the "comments" edge.
  4778  func (m *PostMutation) ResetComments() {
  4779  	m.comments = nil
  4780  	m.clearedcomments = false
  4781  	m.removedcomments = nil
  4782  }
  4783  
  4784  // Where appends a list predicates to the PostMutation builder.
  4785  func (m *PostMutation) Where(ps ...predicate.Post) {
  4786  	m.predicates = append(m.predicates, ps...)
  4787  }
  4788  
  4789  // Op returns the operation name.
  4790  func (m *PostMutation) Op() Op {
  4791  	return m.op
  4792  }
  4793  
  4794  // Type returns the node type of this mutation (Post).
  4795  func (m *PostMutation) Type() string {
  4796  	return m.typ
  4797  }
  4798  
  4799  // Fields returns all fields that were changed during this mutation. Note that in
  4800  // order to get all numeric fields that were incremented/decremented, call
  4801  // AddedFields().
  4802  func (m *PostMutation) Fields() []string {
  4803  	fields := make([]string, 0, 16)
  4804  	if m.created_at != nil {
  4805  		fields = append(fields, post.FieldCreatedAt)
  4806  	}
  4807  	if m.updated_at != nil {
  4808  		fields = append(fields, post.FieldUpdatedAt)
  4809  	}
  4810  	if m.deleted_at != nil {
  4811  		fields = append(fields, post.FieldDeletedAt)
  4812  	}
  4813  	if m.name != nil {
  4814  		fields = append(fields, post.FieldName)
  4815  	}
  4816  	if m.slug != nil {
  4817  		fields = append(fields, post.FieldSlug)
  4818  	}
  4819  	if m.description != nil {
  4820  		fields = append(fields, post.FieldDescription)
  4821  	}
  4822  	if m.content != nil {
  4823  		fields = append(fields, post.FieldContent)
  4824  	}
  4825  	if m.content_html != nil {
  4826  		fields = append(fields, post.FieldContentHTML)
  4827  	}
  4828  	if m.view_count != nil {
  4829  		fields = append(fields, post.FieldViewCount)
  4830  	}
  4831  	if m.comment_count != nil {
  4832  		fields = append(fields, post.FieldCommentCount)
  4833  	}
  4834  	if m.rating_count != nil {
  4835  		fields = append(fields, post.FieldRatingCount)
  4836  	}
  4837  	if m.rating_total != nil {
  4838  		fields = append(fields, post.FieldRatingTotal)
  4839  	}
  4840  	if m.draft != nil {
  4841  		fields = append(fields, post.FieldDraft)
  4842  	}
  4843  	if m.approved != nil {
  4844  		fields = append(fields, post.FieldApproved)
  4845  	}
  4846  	if m.featured_image != nil {
  4847  		fields = append(fields, post.FieldFeaturedImageID)
  4848  	}
  4849  	if m.user != nil {
  4850  		fields = append(fields, post.FieldUserID)
  4851  	}
  4852  	return fields
  4853  }
  4854  
  4855  // Field returns the value of a field with the given name. The second boolean
  4856  // return value indicates that this field was not set, or was not defined in the
  4857  // schema.
  4858  func (m *PostMutation) Field(name string) (ent.Value, bool) {
  4859  	switch name {
  4860  	case post.FieldCreatedAt:
  4861  		return m.CreatedAt()
  4862  	case post.FieldUpdatedAt:
  4863  		return m.UpdatedAt()
  4864  	case post.FieldDeletedAt:
  4865  		return m.DeletedAt()
  4866  	case post.FieldName:
  4867  		return m.Name()
  4868  	case post.FieldSlug:
  4869  		return m.Slug()
  4870  	case post.FieldDescription:
  4871  		return m.Description()
  4872  	case post.FieldContent:
  4873  		return m.Content()
  4874  	case post.FieldContentHTML:
  4875  		return m.ContentHTML()
  4876  	case post.FieldViewCount:
  4877  		return m.ViewCount()
  4878  	case post.FieldCommentCount:
  4879  		return m.CommentCount()
  4880  	case post.FieldRatingCount:
  4881  		return m.RatingCount()
  4882  	case post.FieldRatingTotal:
  4883  		return m.RatingTotal()
  4884  	case post.FieldDraft:
  4885  		return m.Draft()
  4886  	case post.FieldApproved:
  4887  		return m.Approved()
  4888  	case post.FieldFeaturedImageID:
  4889  		return m.FeaturedImageID()
  4890  	case post.FieldUserID:
  4891  		return m.UserID()
  4892  	}
  4893  	return nil, false
  4894  }
  4895  
  4896  // OldField returns the old value of the field from the database. An error is
  4897  // returned if the mutation operation is not UpdateOne, or the query to the
  4898  // database failed.
  4899  func (m *PostMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  4900  	switch name {
  4901  	case post.FieldCreatedAt:
  4902  		return m.OldCreatedAt(ctx)
  4903  	case post.FieldUpdatedAt:
  4904  		return m.OldUpdatedAt(ctx)
  4905  	case post.FieldDeletedAt:
  4906  		return m.OldDeletedAt(ctx)
  4907  	case post.FieldName:
  4908  		return m.OldName(ctx)
  4909  	case post.FieldSlug:
  4910  		return m.OldSlug(ctx)
  4911  	case post.FieldDescription:
  4912  		return m.OldDescription(ctx)
  4913  	case post.FieldContent:
  4914  		return m.OldContent(ctx)
  4915  	case post.FieldContentHTML:
  4916  		return m.OldContentHTML(ctx)
  4917  	case post.FieldViewCount:
  4918  		return m.OldViewCount(ctx)
  4919  	case post.FieldCommentCount:
  4920  		return m.OldCommentCount(ctx)
  4921  	case post.FieldRatingCount:
  4922  		return m.OldRatingCount(ctx)
  4923  	case post.FieldRatingTotal:
  4924  		return m.OldRatingTotal(ctx)
  4925  	case post.FieldDraft:
  4926  		return m.OldDraft(ctx)
  4927  	case post.FieldApproved:
  4928  		return m.OldApproved(ctx)
  4929  	case post.FieldFeaturedImageID:
  4930  		return m.OldFeaturedImageID(ctx)
  4931  	case post.FieldUserID:
  4932  		return m.OldUserID(ctx)
  4933  	}
  4934  	return nil, fmt.Errorf("unknown Post field %s", name)
  4935  }
  4936  
  4937  // SetField sets the value of a field with the given name. It returns an error if
  4938  // the field is not defined in the schema, or if the type mismatched the field
  4939  // type.
  4940  func (m *PostMutation) SetField(name string, value ent.Value) error {
  4941  	switch name {
  4942  	case post.FieldCreatedAt:
  4943  		v, ok := value.(time.Time)
  4944  		if !ok {
  4945  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  4946  		}
  4947  		m.SetCreatedAt(v)
  4948  		return nil
  4949  	case post.FieldUpdatedAt:
  4950  		v, ok := value.(time.Time)
  4951  		if !ok {
  4952  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  4953  		}
  4954  		m.SetUpdatedAt(v)
  4955  		return nil
  4956  	case post.FieldDeletedAt:
  4957  		v, ok := value.(time.Time)
  4958  		if !ok {
  4959  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  4960  		}
  4961  		m.SetDeletedAt(v)
  4962  		return nil
  4963  	case post.FieldName:
  4964  		v, ok := value.(string)
  4965  		if !ok {
  4966  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  4967  		}
  4968  		m.SetName(v)
  4969  		return nil
  4970  	case post.FieldSlug:
  4971  		v, ok := value.(string)
  4972  		if !ok {
  4973  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  4974  		}
  4975  		m.SetSlug(v)
  4976  		return nil
  4977  	case post.FieldDescription:
  4978  		v, ok := value.(string)
  4979  		if !ok {
  4980  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  4981  		}
  4982  		m.SetDescription(v)
  4983  		return nil
  4984  	case post.FieldContent:
  4985  		v, ok := value.(string)
  4986  		if !ok {
  4987  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  4988  		}
  4989  		m.SetContent(v)
  4990  		return nil
  4991  	case post.FieldContentHTML:
  4992  		v, ok := value.(string)
  4993  		if !ok {
  4994  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  4995  		}
  4996  		m.SetContentHTML(v)
  4997  		return nil
  4998  	case post.FieldViewCount:
  4999  		v, ok := value.(int64)
  5000  		if !ok {
  5001  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  5002  		}
  5003  		m.SetViewCount(v)
  5004  		return nil
  5005  	case post.FieldCommentCount:
  5006  		v, ok := value.(int64)
  5007  		if !ok {
  5008  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  5009  		}
  5010  		m.SetCommentCount(v)
  5011  		return nil
  5012  	case post.FieldRatingCount:
  5013  		v, ok := value.(int64)
  5014  		if !ok {
  5015  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  5016  		}
  5017  		m.SetRatingCount(v)
  5018  		return nil
  5019  	case post.FieldRatingTotal:
  5020  		v, ok := value.(int64)
  5021  		if !ok {
  5022  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  5023  		}
  5024  		m.SetRatingTotal(v)
  5025  		return nil
  5026  	case post.FieldDraft:
  5027  		v, ok := value.(bool)
  5028  		if !ok {
  5029  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  5030  		}
  5031  		m.SetDraft(v)
  5032  		return nil
  5033  	case post.FieldApproved:
  5034  		v, ok := value.(bool)
  5035  		if !ok {
  5036  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  5037  		}
  5038  		m.SetApproved(v)
  5039  		return nil
  5040  	case post.FieldFeaturedImageID:
  5041  		v, ok := value.(int)
  5042  		if !ok {
  5043  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  5044  		}
  5045  		m.SetFeaturedImageID(v)
  5046  		return nil
  5047  	case post.FieldUserID:
  5048  		v, ok := value.(int)
  5049  		if !ok {
  5050  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  5051  		}
  5052  		m.SetUserID(v)
  5053  		return nil
  5054  	}
  5055  	return fmt.Errorf("unknown Post field %s", name)
  5056  }
  5057  
  5058  // AddedFields returns all numeric fields that were incremented/decremented during
  5059  // this mutation.
  5060  func (m *PostMutation) AddedFields() []string {
  5061  	var fields []string
  5062  	if m.addview_count != nil {
  5063  		fields = append(fields, post.FieldViewCount)
  5064  	}
  5065  	if m.addcomment_count != nil {
  5066  		fields = append(fields, post.FieldCommentCount)
  5067  	}
  5068  	if m.addrating_count != nil {
  5069  		fields = append(fields, post.FieldRatingCount)
  5070  	}
  5071  	if m.addrating_total != nil {
  5072  		fields = append(fields, post.FieldRatingTotal)
  5073  	}
  5074  	return fields
  5075  }
  5076  
  5077  // AddedField returns the numeric value that was incremented/decremented on a field
  5078  // with the given name. The second boolean return value indicates that this field
  5079  // was not set, or was not defined in the schema.
  5080  func (m *PostMutation) AddedField(name string) (ent.Value, bool) {
  5081  	switch name {
  5082  	case post.FieldViewCount:
  5083  		return m.AddedViewCount()
  5084  	case post.FieldCommentCount:
  5085  		return m.AddedCommentCount()
  5086  	case post.FieldRatingCount:
  5087  		return m.AddedRatingCount()
  5088  	case post.FieldRatingTotal:
  5089  		return m.AddedRatingTotal()
  5090  	}
  5091  	return nil, false
  5092  }
  5093  
  5094  // AddField adds the value to the field with the given name. It returns an error if
  5095  // the field is not defined in the schema, or if the type mismatched the field
  5096  // type.
  5097  func (m *PostMutation) AddField(name string, value ent.Value) error {
  5098  	switch name {
  5099  	case post.FieldViewCount:
  5100  		v, ok := value.(int64)
  5101  		if !ok {
  5102  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  5103  		}
  5104  		m.AddViewCount(v)
  5105  		return nil
  5106  	case post.FieldCommentCount:
  5107  		v, ok := value.(int64)
  5108  		if !ok {
  5109  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  5110  		}
  5111  		m.AddCommentCount(v)
  5112  		return nil
  5113  	case post.FieldRatingCount:
  5114  		v, ok := value.(int64)
  5115  		if !ok {
  5116  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  5117  		}
  5118  		m.AddRatingCount(v)
  5119  		return nil
  5120  	case post.FieldRatingTotal:
  5121  		v, ok := value.(int64)
  5122  		if !ok {
  5123  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  5124  		}
  5125  		m.AddRatingTotal(v)
  5126  		return nil
  5127  	}
  5128  	return fmt.Errorf("unknown Post numeric field %s", name)
  5129  }
  5130  
  5131  // ClearedFields returns all nullable fields that were cleared during this
  5132  // mutation.
  5133  func (m *PostMutation) ClearedFields() []string {
  5134  	var fields []string
  5135  	if m.FieldCleared(post.FieldDeletedAt) {
  5136  		fields = append(fields, post.FieldDeletedAt)
  5137  	}
  5138  	if m.FieldCleared(post.FieldDescription) {
  5139  		fields = append(fields, post.FieldDescription)
  5140  	}
  5141  	if m.FieldCleared(post.FieldRatingCount) {
  5142  		fields = append(fields, post.FieldRatingCount)
  5143  	}
  5144  	if m.FieldCleared(post.FieldRatingTotal) {
  5145  		fields = append(fields, post.FieldRatingTotal)
  5146  	}
  5147  	if m.FieldCleared(post.FieldDraft) {
  5148  		fields = append(fields, post.FieldDraft)
  5149  	}
  5150  	if m.FieldCleared(post.FieldApproved) {
  5151  		fields = append(fields, post.FieldApproved)
  5152  	}
  5153  	if m.FieldCleared(post.FieldFeaturedImageID) {
  5154  		fields = append(fields, post.FieldFeaturedImageID)
  5155  	}
  5156  	if m.FieldCleared(post.FieldUserID) {
  5157  		fields = append(fields, post.FieldUserID)
  5158  	}
  5159  	return fields
  5160  }
  5161  
  5162  // FieldCleared returns a boolean indicating if a field with the given name was
  5163  // cleared in this mutation.
  5164  func (m *PostMutation) FieldCleared(name string) bool {
  5165  	_, ok := m.clearedFields[name]
  5166  	return ok
  5167  }
  5168  
  5169  // ClearField clears the value of the field with the given name. It returns an
  5170  // error if the field is not defined in the schema.
  5171  func (m *PostMutation) ClearField(name string) error {
  5172  	switch name {
  5173  	case post.FieldDeletedAt:
  5174  		m.ClearDeletedAt()
  5175  		return nil
  5176  	case post.FieldDescription:
  5177  		m.ClearDescription()
  5178  		return nil
  5179  	case post.FieldRatingCount:
  5180  		m.ClearRatingCount()
  5181  		return nil
  5182  	case post.FieldRatingTotal:
  5183  		m.ClearRatingTotal()
  5184  		return nil
  5185  	case post.FieldDraft:
  5186  		m.ClearDraft()
  5187  		return nil
  5188  	case post.FieldApproved:
  5189  		m.ClearApproved()
  5190  		return nil
  5191  	case post.FieldFeaturedImageID:
  5192  		m.ClearFeaturedImageID()
  5193  		return nil
  5194  	case post.FieldUserID:
  5195  		m.ClearUserID()
  5196  		return nil
  5197  	}
  5198  	return fmt.Errorf("unknown Post nullable field %s", name)
  5199  }
  5200  
  5201  // ResetField resets all changes in the mutation for the field with the given name.
  5202  // It returns an error if the field is not defined in the schema.
  5203  func (m *PostMutation) ResetField(name string) error {
  5204  	switch name {
  5205  	case post.FieldCreatedAt:
  5206  		m.ResetCreatedAt()
  5207  		return nil
  5208  	case post.FieldUpdatedAt:
  5209  		m.ResetUpdatedAt()
  5210  		return nil
  5211  	case post.FieldDeletedAt:
  5212  		m.ResetDeletedAt()
  5213  		return nil
  5214  	case post.FieldName:
  5215  		m.ResetName()
  5216  		return nil
  5217  	case post.FieldSlug:
  5218  		m.ResetSlug()
  5219  		return nil
  5220  	case post.FieldDescription:
  5221  		m.ResetDescription()
  5222  		return nil
  5223  	case post.FieldContent:
  5224  		m.ResetContent()
  5225  		return nil
  5226  	case post.FieldContentHTML:
  5227  		m.ResetContentHTML()
  5228  		return nil
  5229  	case post.FieldViewCount:
  5230  		m.ResetViewCount()
  5231  		return nil
  5232  	case post.FieldCommentCount:
  5233  		m.ResetCommentCount()
  5234  		return nil
  5235  	case post.FieldRatingCount:
  5236  		m.ResetRatingCount()
  5237  		return nil
  5238  	case post.FieldRatingTotal:
  5239  		m.ResetRatingTotal()
  5240  		return nil
  5241  	case post.FieldDraft:
  5242  		m.ResetDraft()
  5243  		return nil
  5244  	case post.FieldApproved:
  5245  		m.ResetApproved()
  5246  		return nil
  5247  	case post.FieldFeaturedImageID:
  5248  		m.ResetFeaturedImageID()
  5249  		return nil
  5250  	case post.FieldUserID:
  5251  		m.ResetUserID()
  5252  		return nil
  5253  	}
  5254  	return fmt.Errorf("unknown Post field %s", name)
  5255  }
  5256  
  5257  // AddedEdges returns all edge names that were set/added in this mutation.
  5258  func (m *PostMutation) AddedEdges() []string {
  5259  	edges := make([]string, 0, 4)
  5260  	if m.user != nil {
  5261  		edges = append(edges, post.EdgeUser)
  5262  	}
  5263  	if m.topics != nil {
  5264  		edges = append(edges, post.EdgeTopics)
  5265  	}
  5266  	if m.featured_image != nil {
  5267  		edges = append(edges, post.EdgeFeaturedImage)
  5268  	}
  5269  	if m.comments != nil {
  5270  		edges = append(edges, post.EdgeComments)
  5271  	}
  5272  	return edges
  5273  }
  5274  
  5275  // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  5276  // name in this mutation.
  5277  func (m *PostMutation) AddedIDs(name string) []ent.Value {
  5278  	switch name {
  5279  	case post.EdgeUser:
  5280  		if id := m.user; id != nil {
  5281  			return []ent.Value{*id}
  5282  		}
  5283  	case post.EdgeTopics:
  5284  		ids := make([]ent.Value, 0, len(m.topics))
  5285  		for id := range m.topics {
  5286  			ids = append(ids, id)
  5287  		}
  5288  		return ids
  5289  	case post.EdgeFeaturedImage:
  5290  		if id := m.featured_image; id != nil {
  5291  			return []ent.Value{*id}
  5292  		}
  5293  	case post.EdgeComments:
  5294  		ids := make([]ent.Value, 0, len(m.comments))
  5295  		for id := range m.comments {
  5296  			ids = append(ids, id)
  5297  		}
  5298  		return ids
  5299  	}
  5300  	return nil
  5301  }
  5302  
  5303  // RemovedEdges returns all edge names that were removed in this mutation.
  5304  func (m *PostMutation) RemovedEdges() []string {
  5305  	edges := make([]string, 0, 4)
  5306  	if m.removedtopics != nil {
  5307  		edges = append(edges, post.EdgeTopics)
  5308  	}
  5309  	if m.removedcomments != nil {
  5310  		edges = append(edges, post.EdgeComments)
  5311  	}
  5312  	return edges
  5313  }
  5314  
  5315  // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  5316  // the given name in this mutation.
  5317  func (m *PostMutation) RemovedIDs(name string) []ent.Value {
  5318  	switch name {
  5319  	case post.EdgeTopics:
  5320  		ids := make([]ent.Value, 0, len(m.removedtopics))
  5321  		for id := range m.removedtopics {
  5322  			ids = append(ids, id)
  5323  		}
  5324  		return ids
  5325  	case post.EdgeComments:
  5326  		ids := make([]ent.Value, 0, len(m.removedcomments))
  5327  		for id := range m.removedcomments {
  5328  			ids = append(ids, id)
  5329  		}
  5330  		return ids
  5331  	}
  5332  	return nil
  5333  }
  5334  
  5335  // ClearedEdges returns all edge names that were cleared in this mutation.
  5336  func (m *PostMutation) ClearedEdges() []string {
  5337  	edges := make([]string, 0, 4)
  5338  	if m.cleareduser {
  5339  		edges = append(edges, post.EdgeUser)
  5340  	}
  5341  	if m.clearedtopics {
  5342  		edges = append(edges, post.EdgeTopics)
  5343  	}
  5344  	if m.clearedfeatured_image {
  5345  		edges = append(edges, post.EdgeFeaturedImage)
  5346  	}
  5347  	if m.clearedcomments {
  5348  		edges = append(edges, post.EdgeComments)
  5349  	}
  5350  	return edges
  5351  }
  5352  
  5353  // EdgeCleared returns a boolean which indicates if the edge with the given name
  5354  // was cleared in this mutation.
  5355  func (m *PostMutation) EdgeCleared(name string) bool {
  5356  	switch name {
  5357  	case post.EdgeUser:
  5358  		return m.cleareduser
  5359  	case post.EdgeTopics:
  5360  		return m.clearedtopics
  5361  	case post.EdgeFeaturedImage:
  5362  		return m.clearedfeatured_image
  5363  	case post.EdgeComments:
  5364  		return m.clearedcomments
  5365  	}
  5366  	return false
  5367  }
  5368  
  5369  // ClearEdge clears the value of the edge with the given name. It returns an error
  5370  // if that edge is not defined in the schema.
  5371  func (m *PostMutation) ClearEdge(name string) error {
  5372  	switch name {
  5373  	case post.EdgeUser:
  5374  		m.ClearUser()
  5375  		return nil
  5376  	case post.EdgeFeaturedImage:
  5377  		m.ClearFeaturedImage()
  5378  		return nil
  5379  	}
  5380  	return fmt.Errorf("unknown Post unique edge %s", name)
  5381  }
  5382  
  5383  // ResetEdge resets all changes to the edge with the given name in this mutation.
  5384  // It returns an error if the edge is not defined in the schema.
  5385  func (m *PostMutation) ResetEdge(name string) error {
  5386  	switch name {
  5387  	case post.EdgeUser:
  5388  		m.ResetUser()
  5389  		return nil
  5390  	case post.EdgeTopics:
  5391  		m.ResetTopics()
  5392  		return nil
  5393  	case post.EdgeFeaturedImage:
  5394  		m.ResetFeaturedImage()
  5395  		return nil
  5396  	case post.EdgeComments:
  5397  		m.ResetComments()
  5398  		return nil
  5399  	}
  5400  	return fmt.Errorf("unknown Post edge %s", name)
  5401  }
  5402  
  5403  // RoleMutation represents an operation that mutates the Role nodes in the graph.
  5404  type RoleMutation struct {
  5405  	config
  5406  	op                 Op
  5407  	typ                string
  5408  	id                 *int
  5409  	created_at         *time.Time
  5410  	updated_at         *time.Time
  5411  	deleted_at         *time.Time
  5412  	name               *string
  5413  	description        *string
  5414  	root               *bool
  5415  	clearedFields      map[string]struct{}
  5416  	permissions        map[int]struct{}
  5417  	removedpermissions map[int]struct{}
  5418  	clearedpermissions bool
  5419  	users              map[int]struct{}
  5420  	removedusers       map[int]struct{}
  5421  	clearedusers       bool
  5422  	done               bool
  5423  	oldValue           func(context.Context) (*Role, error)
  5424  	predicates         []predicate.Role
  5425  }
  5426  
  5427  var _ ent.Mutation = (*RoleMutation)(nil)
  5428  
  5429  // roleOption allows management of the mutation configuration using functional options.
  5430  type roleOption func(*RoleMutation)
  5431  
  5432  // newRoleMutation creates new mutation for the Role entity.
  5433  func newRoleMutation(c config, op Op, opts ...roleOption) *RoleMutation {
  5434  	m := &RoleMutation{
  5435  		config:        c,
  5436  		op:            op,
  5437  		typ:           TypeRole,
  5438  		clearedFields: make(map[string]struct{}),
  5439  	}
  5440  	for _, opt := range opts {
  5441  		opt(m)
  5442  	}
  5443  	return m
  5444  }
  5445  
  5446  // withRoleID sets the ID field of the mutation.
  5447  func withRoleID(id int) roleOption {
  5448  	return func(m *RoleMutation) {
  5449  		var (
  5450  			err   error
  5451  			once  sync.Once
  5452  			value *Role
  5453  		)
  5454  		m.oldValue = func(ctx context.Context) (*Role, error) {
  5455  			once.Do(func() {
  5456  				if m.done {
  5457  					err = errors.New("querying old values post mutation is not allowed")
  5458  				} else {
  5459  					value, err = m.Client().Role.Get(ctx, id)
  5460  				}
  5461  			})
  5462  			return value, err
  5463  		}
  5464  		m.id = &id
  5465  	}
  5466  }
  5467  
  5468  // withRole sets the old Role of the mutation.
  5469  func withRole(node *Role) roleOption {
  5470  	return func(m *RoleMutation) {
  5471  		m.oldValue = func(context.Context) (*Role, error) {
  5472  			return node, nil
  5473  		}
  5474  		m.id = &node.ID
  5475  	}
  5476  }
  5477  
  5478  // Client returns a new `ent.Client` from the mutation. If the mutation was
  5479  // executed in a transaction (ent.Tx), a transactional client is returned.
  5480  func (m RoleMutation) Client() *Client {
  5481  	client := &Client{config: m.config}
  5482  	client.init()
  5483  	return client
  5484  }
  5485  
  5486  // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  5487  // it returns an error otherwise.
  5488  func (m RoleMutation) Tx() (*Tx, error) {
  5489  	if _, ok := m.driver.(*txDriver); !ok {
  5490  		return nil, errors.New("ent: mutation is not running in a transaction")
  5491  	}
  5492  	tx := &Tx{config: m.config}
  5493  	tx.init()
  5494  	return tx, nil
  5495  }
  5496  
  5497  // ID returns the ID value in the mutation. Note that the ID is only available
  5498  // if it was provided to the builder or after it was returned from the database.
  5499  func (m *RoleMutation) ID() (id int, exists bool) {
  5500  	if m.id == nil {
  5501  		return
  5502  	}
  5503  	return *m.id, true
  5504  }
  5505  
  5506  // IDs queries the database and returns the entity ids that match the mutation's predicate.
  5507  // That means, if the mutation is applied within a transaction with an isolation level such
  5508  // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  5509  // or updated by the mutation.
  5510  func (m *RoleMutation) IDs(ctx context.Context) ([]int, error) {
  5511  	switch {
  5512  	case m.op.Is(OpUpdateOne | OpDeleteOne):
  5513  		id, exists := m.ID()
  5514  		if exists {
  5515  			return []int{id}, nil
  5516  		}
  5517  		fallthrough
  5518  	case m.op.Is(OpUpdate | OpDelete):
  5519  		return m.Client().Role.Query().Where(m.predicates...).IDs(ctx)
  5520  	default:
  5521  		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  5522  	}
  5523  }
  5524  
  5525  // SetCreatedAt sets the "created_at" field.
  5526  func (m *RoleMutation) SetCreatedAt(t time.Time) {
  5527  	m.created_at = &t
  5528  }
  5529  
  5530  // CreatedAt returns the value of the "created_at" field in the mutation.
  5531  func (m *RoleMutation) CreatedAt() (r time.Time, exists bool) {
  5532  	v := m.created_at
  5533  	if v == nil {
  5534  		return
  5535  	}
  5536  	return *v, true
  5537  }
  5538  
  5539  // OldCreatedAt returns the old "created_at" field's value of the Role entity.
  5540  // If the Role object wasn't provided to the builder, the object is fetched from the database.
  5541  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5542  func (m *RoleMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  5543  	if !m.op.Is(OpUpdateOne) {
  5544  		return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  5545  	}
  5546  	if m.id == nil || m.oldValue == nil {
  5547  		return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  5548  	}
  5549  	oldValue, err := m.oldValue(ctx)
  5550  	if err != nil {
  5551  		return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  5552  	}
  5553  	return oldValue.CreatedAt, nil
  5554  }
  5555  
  5556  // ResetCreatedAt resets all changes to the "created_at" field.
  5557  func (m *RoleMutation) ResetCreatedAt() {
  5558  	m.created_at = nil
  5559  }
  5560  
  5561  // SetUpdatedAt sets the "updated_at" field.
  5562  func (m *RoleMutation) SetUpdatedAt(t time.Time) {
  5563  	m.updated_at = &t
  5564  }
  5565  
  5566  // UpdatedAt returns the value of the "updated_at" field in the mutation.
  5567  func (m *RoleMutation) UpdatedAt() (r time.Time, exists bool) {
  5568  	v := m.updated_at
  5569  	if v == nil {
  5570  		return
  5571  	}
  5572  	return *v, true
  5573  }
  5574  
  5575  // OldUpdatedAt returns the old "updated_at" field's value of the Role entity.
  5576  // If the Role object wasn't provided to the builder, the object is fetched from the database.
  5577  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5578  func (m *RoleMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  5579  	if !m.op.Is(OpUpdateOne) {
  5580  		return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  5581  	}
  5582  	if m.id == nil || m.oldValue == nil {
  5583  		return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  5584  	}
  5585  	oldValue, err := m.oldValue(ctx)
  5586  	if err != nil {
  5587  		return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  5588  	}
  5589  	return oldValue.UpdatedAt, nil
  5590  }
  5591  
  5592  // ResetUpdatedAt resets all changes to the "updated_at" field.
  5593  func (m *RoleMutation) ResetUpdatedAt() {
  5594  	m.updated_at = nil
  5595  }
  5596  
  5597  // SetDeletedAt sets the "deleted_at" field.
  5598  func (m *RoleMutation) SetDeletedAt(t time.Time) {
  5599  	m.deleted_at = &t
  5600  }
  5601  
  5602  // DeletedAt returns the value of the "deleted_at" field in the mutation.
  5603  func (m *RoleMutation) DeletedAt() (r time.Time, exists bool) {
  5604  	v := m.deleted_at
  5605  	if v == nil {
  5606  		return
  5607  	}
  5608  	return *v, true
  5609  }
  5610  
  5611  // OldDeletedAt returns the old "deleted_at" field's value of the Role entity.
  5612  // If the Role object wasn't provided to the builder, the object is fetched from the database.
  5613  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5614  func (m *RoleMutation) OldDeletedAt(ctx context.Context) (v time.Time, err error) {
  5615  	if !m.op.Is(OpUpdateOne) {
  5616  		return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
  5617  	}
  5618  	if m.id == nil || m.oldValue == nil {
  5619  		return v, errors.New("OldDeletedAt requires an ID field in the mutation")
  5620  	}
  5621  	oldValue, err := m.oldValue(ctx)
  5622  	if err != nil {
  5623  		return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
  5624  	}
  5625  	return oldValue.DeletedAt, nil
  5626  }
  5627  
  5628  // ClearDeletedAt clears the value of the "deleted_at" field.
  5629  func (m *RoleMutation) ClearDeletedAt() {
  5630  	m.deleted_at = nil
  5631  	m.clearedFields[role.FieldDeletedAt] = struct{}{}
  5632  }
  5633  
  5634  // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
  5635  func (m *RoleMutation) DeletedAtCleared() bool {
  5636  	_, ok := m.clearedFields[role.FieldDeletedAt]
  5637  	return ok
  5638  }
  5639  
  5640  // ResetDeletedAt resets all changes to the "deleted_at" field.
  5641  func (m *RoleMutation) ResetDeletedAt() {
  5642  	m.deleted_at = nil
  5643  	delete(m.clearedFields, role.FieldDeletedAt)
  5644  }
  5645  
  5646  // SetName sets the "name" field.
  5647  func (m *RoleMutation) SetName(s string) {
  5648  	m.name = &s
  5649  }
  5650  
  5651  // Name returns the value of the "name" field in the mutation.
  5652  func (m *RoleMutation) Name() (r string, exists bool) {
  5653  	v := m.name
  5654  	if v == nil {
  5655  		return
  5656  	}
  5657  	return *v, true
  5658  }
  5659  
  5660  // OldName returns the old "name" field's value of the Role entity.
  5661  // If the Role object wasn't provided to the builder, the object is fetched from the database.
  5662  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5663  func (m *RoleMutation) OldName(ctx context.Context) (v string, err error) {
  5664  	if !m.op.Is(OpUpdateOne) {
  5665  		return v, errors.New("OldName is only allowed on UpdateOne operations")
  5666  	}
  5667  	if m.id == nil || m.oldValue == nil {
  5668  		return v, errors.New("OldName requires an ID field in the mutation")
  5669  	}
  5670  	oldValue, err := m.oldValue(ctx)
  5671  	if err != nil {
  5672  		return v, fmt.Errorf("querying old value for OldName: %w", err)
  5673  	}
  5674  	return oldValue.Name, nil
  5675  }
  5676  
  5677  // ResetName resets all changes to the "name" field.
  5678  func (m *RoleMutation) ResetName() {
  5679  	m.name = nil
  5680  }
  5681  
  5682  // SetDescription sets the "description" field.
  5683  func (m *RoleMutation) SetDescription(s string) {
  5684  	m.description = &s
  5685  }
  5686  
  5687  // Description returns the value of the "description" field in the mutation.
  5688  func (m *RoleMutation) Description() (r string, exists bool) {
  5689  	v := m.description
  5690  	if v == nil {
  5691  		return
  5692  	}
  5693  	return *v, true
  5694  }
  5695  
  5696  // OldDescription returns the old "description" field's value of the Role entity.
  5697  // If the Role object wasn't provided to the builder, the object is fetched from the database.
  5698  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5699  func (m *RoleMutation) OldDescription(ctx context.Context) (v string, err error) {
  5700  	if !m.op.Is(OpUpdateOne) {
  5701  		return v, errors.New("OldDescription is only allowed on UpdateOne operations")
  5702  	}
  5703  	if m.id == nil || m.oldValue == nil {
  5704  		return v, errors.New("OldDescription requires an ID field in the mutation")
  5705  	}
  5706  	oldValue, err := m.oldValue(ctx)
  5707  	if err != nil {
  5708  		return v, fmt.Errorf("querying old value for OldDescription: %w", err)
  5709  	}
  5710  	return oldValue.Description, nil
  5711  }
  5712  
  5713  // ClearDescription clears the value of the "description" field.
  5714  func (m *RoleMutation) ClearDescription() {
  5715  	m.description = nil
  5716  	m.clearedFields[role.FieldDescription] = struct{}{}
  5717  }
  5718  
  5719  // DescriptionCleared returns if the "description" field was cleared in this mutation.
  5720  func (m *RoleMutation) DescriptionCleared() bool {
  5721  	_, ok := m.clearedFields[role.FieldDescription]
  5722  	return ok
  5723  }
  5724  
  5725  // ResetDescription resets all changes to the "description" field.
  5726  func (m *RoleMutation) ResetDescription() {
  5727  	m.description = nil
  5728  	delete(m.clearedFields, role.FieldDescription)
  5729  }
  5730  
  5731  // SetRoot sets the "root" field.
  5732  func (m *RoleMutation) SetRoot(b bool) {
  5733  	m.root = &b
  5734  }
  5735  
  5736  // Root returns the value of the "root" field in the mutation.
  5737  func (m *RoleMutation) Root() (r bool, exists bool) {
  5738  	v := m.root
  5739  	if v == nil {
  5740  		return
  5741  	}
  5742  	return *v, true
  5743  }
  5744  
  5745  // OldRoot returns the old "root" field's value of the Role entity.
  5746  // If the Role object wasn't provided to the builder, the object is fetched from the database.
  5747  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  5748  func (m *RoleMutation) OldRoot(ctx context.Context) (v bool, err error) {
  5749  	if !m.op.Is(OpUpdateOne) {
  5750  		return v, errors.New("OldRoot is only allowed on UpdateOne operations")
  5751  	}
  5752  	if m.id == nil || m.oldValue == nil {
  5753  		return v, errors.New("OldRoot requires an ID field in the mutation")
  5754  	}
  5755  	oldValue, err := m.oldValue(ctx)
  5756  	if err != nil {
  5757  		return v, fmt.Errorf("querying old value for OldRoot: %w", err)
  5758  	}
  5759  	return oldValue.Root, nil
  5760  }
  5761  
  5762  // ClearRoot clears the value of the "root" field.
  5763  func (m *RoleMutation) ClearRoot() {
  5764  	m.root = nil
  5765  	m.clearedFields[role.FieldRoot] = struct{}{}
  5766  }
  5767  
  5768  // RootCleared returns if the "root" field was cleared in this mutation.
  5769  func (m *RoleMutation) RootCleared() bool {
  5770  	_, ok := m.clearedFields[role.FieldRoot]
  5771  	return ok
  5772  }
  5773  
  5774  // ResetRoot resets all changes to the "root" field.
  5775  func (m *RoleMutation) ResetRoot() {
  5776  	m.root = nil
  5777  	delete(m.clearedFields, role.FieldRoot)
  5778  }
  5779  
  5780  // AddPermissionIDs adds the "permissions" edge to the Permission entity by ids.
  5781  func (m *RoleMutation) AddPermissionIDs(ids ...int) {
  5782  	if m.permissions == nil {
  5783  		m.permissions = make(map[int]struct{})
  5784  	}
  5785  	for i := range ids {
  5786  		m.permissions[ids[i]] = struct{}{}
  5787  	}
  5788  }
  5789  
  5790  // ClearPermissions clears the "permissions" edge to the Permission entity.
  5791  func (m *RoleMutation) ClearPermissions() {
  5792  	m.clearedpermissions = true
  5793  }
  5794  
  5795  // PermissionsCleared reports if the "permissions" edge to the Permission entity was cleared.
  5796  func (m *RoleMutation) PermissionsCleared() bool {
  5797  	return m.clearedpermissions
  5798  }
  5799  
  5800  // RemovePermissionIDs removes the "permissions" edge to the Permission entity by IDs.
  5801  func (m *RoleMutation) RemovePermissionIDs(ids ...int) {
  5802  	if m.removedpermissions == nil {
  5803  		m.removedpermissions = make(map[int]struct{})
  5804  	}
  5805  	for i := range ids {
  5806  		delete(m.permissions, ids[i])
  5807  		m.removedpermissions[ids[i]] = struct{}{}
  5808  	}
  5809  }
  5810  
  5811  // RemovedPermissions returns the removed IDs of the "permissions" edge to the Permission entity.
  5812  func (m *RoleMutation) RemovedPermissionsIDs() (ids []int) {
  5813  	for id := range m.removedpermissions {
  5814  		ids = append(ids, id)
  5815  	}
  5816  	return
  5817  }
  5818  
  5819  // PermissionsIDs returns the "permissions" edge IDs in the mutation.
  5820  func (m *RoleMutation) PermissionsIDs() (ids []int) {
  5821  	for id := range m.permissions {
  5822  		ids = append(ids, id)
  5823  	}
  5824  	return
  5825  }
  5826  
  5827  // ResetPermissions resets all changes to the "permissions" edge.
  5828  func (m *RoleMutation) ResetPermissions() {
  5829  	m.permissions = nil
  5830  	m.clearedpermissions = false
  5831  	m.removedpermissions = nil
  5832  }
  5833  
  5834  // AddUserIDs adds the "users" edge to the User entity by ids.
  5835  func (m *RoleMutation) AddUserIDs(ids ...int) {
  5836  	if m.users == nil {
  5837  		m.users = make(map[int]struct{})
  5838  	}
  5839  	for i := range ids {
  5840  		m.users[ids[i]] = struct{}{}
  5841  	}
  5842  }
  5843  
  5844  // ClearUsers clears the "users" edge to the User entity.
  5845  func (m *RoleMutation) ClearUsers() {
  5846  	m.clearedusers = true
  5847  }
  5848  
  5849  // UsersCleared reports if the "users" edge to the User entity was cleared.
  5850  func (m *RoleMutation) UsersCleared() bool {
  5851  	return m.clearedusers
  5852  }
  5853  
  5854  // RemoveUserIDs removes the "users" edge to the User entity by IDs.
  5855  func (m *RoleMutation) RemoveUserIDs(ids ...int) {
  5856  	if m.removedusers == nil {
  5857  		m.removedusers = make(map[int]struct{})
  5858  	}
  5859  	for i := range ids {
  5860  		delete(m.users, ids[i])
  5861  		m.removedusers[ids[i]] = struct{}{}
  5862  	}
  5863  }
  5864  
  5865  // RemovedUsers returns the removed IDs of the "users" edge to the User entity.
  5866  func (m *RoleMutation) RemovedUsersIDs() (ids []int) {
  5867  	for id := range m.removedusers {
  5868  		ids = append(ids, id)
  5869  	}
  5870  	return
  5871  }
  5872  
  5873  // UsersIDs returns the "users" edge IDs in the mutation.
  5874  func (m *RoleMutation) UsersIDs() (ids []int) {
  5875  	for id := range m.users {
  5876  		ids = append(ids, id)
  5877  	}
  5878  	return
  5879  }
  5880  
  5881  // ResetUsers resets all changes to the "users" edge.
  5882  func (m *RoleMutation) ResetUsers() {
  5883  	m.users = nil
  5884  	m.clearedusers = false
  5885  	m.removedusers = nil
  5886  }
  5887  
  5888  // Where appends a list predicates to the RoleMutation builder.
  5889  func (m *RoleMutation) Where(ps ...predicate.Role) {
  5890  	m.predicates = append(m.predicates, ps...)
  5891  }
  5892  
  5893  // Op returns the operation name.
  5894  func (m *RoleMutation) Op() Op {
  5895  	return m.op
  5896  }
  5897  
  5898  // Type returns the node type of this mutation (Role).
  5899  func (m *RoleMutation) Type() string {
  5900  	return m.typ
  5901  }
  5902  
  5903  // Fields returns all fields that were changed during this mutation. Note that in
  5904  // order to get all numeric fields that were incremented/decremented, call
  5905  // AddedFields().
  5906  func (m *RoleMutation) Fields() []string {
  5907  	fields := make([]string, 0, 6)
  5908  	if m.created_at != nil {
  5909  		fields = append(fields, role.FieldCreatedAt)
  5910  	}
  5911  	if m.updated_at != nil {
  5912  		fields = append(fields, role.FieldUpdatedAt)
  5913  	}
  5914  	if m.deleted_at != nil {
  5915  		fields = append(fields, role.FieldDeletedAt)
  5916  	}
  5917  	if m.name != nil {
  5918  		fields = append(fields, role.FieldName)
  5919  	}
  5920  	if m.description != nil {
  5921  		fields = append(fields, role.FieldDescription)
  5922  	}
  5923  	if m.root != nil {
  5924  		fields = append(fields, role.FieldRoot)
  5925  	}
  5926  	return fields
  5927  }
  5928  
  5929  // Field returns the value of a field with the given name. The second boolean
  5930  // return value indicates that this field was not set, or was not defined in the
  5931  // schema.
  5932  func (m *RoleMutation) Field(name string) (ent.Value, bool) {
  5933  	switch name {
  5934  	case role.FieldCreatedAt:
  5935  		return m.CreatedAt()
  5936  	case role.FieldUpdatedAt:
  5937  		return m.UpdatedAt()
  5938  	case role.FieldDeletedAt:
  5939  		return m.DeletedAt()
  5940  	case role.FieldName:
  5941  		return m.Name()
  5942  	case role.FieldDescription:
  5943  		return m.Description()
  5944  	case role.FieldRoot:
  5945  		return m.Root()
  5946  	}
  5947  	return nil, false
  5948  }
  5949  
  5950  // OldField returns the old value of the field from the database. An error is
  5951  // returned if the mutation operation is not UpdateOne, or the query to the
  5952  // database failed.
  5953  func (m *RoleMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  5954  	switch name {
  5955  	case role.FieldCreatedAt:
  5956  		return m.OldCreatedAt(ctx)
  5957  	case role.FieldUpdatedAt:
  5958  		return m.OldUpdatedAt(ctx)
  5959  	case role.FieldDeletedAt:
  5960  		return m.OldDeletedAt(ctx)
  5961  	case role.FieldName:
  5962  		return m.OldName(ctx)
  5963  	case role.FieldDescription:
  5964  		return m.OldDescription(ctx)
  5965  	case role.FieldRoot:
  5966  		return m.OldRoot(ctx)
  5967  	}
  5968  	return nil, fmt.Errorf("unknown Role field %s", name)
  5969  }
  5970  
  5971  // SetField sets the value of a field with the given name. It returns an error if
  5972  // the field is not defined in the schema, or if the type mismatched the field
  5973  // type.
  5974  func (m *RoleMutation) SetField(name string, value ent.Value) error {
  5975  	switch name {
  5976  	case role.FieldCreatedAt:
  5977  		v, ok := value.(time.Time)
  5978  		if !ok {
  5979  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  5980  		}
  5981  		m.SetCreatedAt(v)
  5982  		return nil
  5983  	case role.FieldUpdatedAt:
  5984  		v, ok := value.(time.Time)
  5985  		if !ok {
  5986  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  5987  		}
  5988  		m.SetUpdatedAt(v)
  5989  		return nil
  5990  	case role.FieldDeletedAt:
  5991  		v, ok := value.(time.Time)
  5992  		if !ok {
  5993  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  5994  		}
  5995  		m.SetDeletedAt(v)
  5996  		return nil
  5997  	case role.FieldName:
  5998  		v, ok := value.(string)
  5999  		if !ok {
  6000  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  6001  		}
  6002  		m.SetName(v)
  6003  		return nil
  6004  	case role.FieldDescription:
  6005  		v, ok := value.(string)
  6006  		if !ok {
  6007  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  6008  		}
  6009  		m.SetDescription(v)
  6010  		return nil
  6011  	case role.FieldRoot:
  6012  		v, ok := value.(bool)
  6013  		if !ok {
  6014  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  6015  		}
  6016  		m.SetRoot(v)
  6017  		return nil
  6018  	}
  6019  	return fmt.Errorf("unknown Role field %s", name)
  6020  }
  6021  
  6022  // AddedFields returns all numeric fields that were incremented/decremented during
  6023  // this mutation.
  6024  func (m *RoleMutation) AddedFields() []string {
  6025  	return nil
  6026  }
  6027  
  6028  // AddedField returns the numeric value that was incremented/decremented on a field
  6029  // with the given name. The second boolean return value indicates that this field
  6030  // was not set, or was not defined in the schema.
  6031  func (m *RoleMutation) AddedField(name string) (ent.Value, bool) {
  6032  	return nil, false
  6033  }
  6034  
  6035  // AddField adds the value to the field with the given name. It returns an error if
  6036  // the field is not defined in the schema, or if the type mismatched the field
  6037  // type.
  6038  func (m *RoleMutation) AddField(name string, value ent.Value) error {
  6039  	switch name {
  6040  	}
  6041  	return fmt.Errorf("unknown Role numeric field %s", name)
  6042  }
  6043  
  6044  // ClearedFields returns all nullable fields that were cleared during this
  6045  // mutation.
  6046  func (m *RoleMutation) ClearedFields() []string {
  6047  	var fields []string
  6048  	if m.FieldCleared(role.FieldDeletedAt) {
  6049  		fields = append(fields, role.FieldDeletedAt)
  6050  	}
  6051  	if m.FieldCleared(role.FieldDescription) {
  6052  		fields = append(fields, role.FieldDescription)
  6053  	}
  6054  	if m.FieldCleared(role.FieldRoot) {
  6055  		fields = append(fields, role.FieldRoot)
  6056  	}
  6057  	return fields
  6058  }
  6059  
  6060  // FieldCleared returns a boolean indicating if a field with the given name was
  6061  // cleared in this mutation.
  6062  func (m *RoleMutation) FieldCleared(name string) bool {
  6063  	_, ok := m.clearedFields[name]
  6064  	return ok
  6065  }
  6066  
  6067  // ClearField clears the value of the field with the given name. It returns an
  6068  // error if the field is not defined in the schema.
  6069  func (m *RoleMutation) ClearField(name string) error {
  6070  	switch name {
  6071  	case role.FieldDeletedAt:
  6072  		m.ClearDeletedAt()
  6073  		return nil
  6074  	case role.FieldDescription:
  6075  		m.ClearDescription()
  6076  		return nil
  6077  	case role.FieldRoot:
  6078  		m.ClearRoot()
  6079  		return nil
  6080  	}
  6081  	return fmt.Errorf("unknown Role nullable field %s", name)
  6082  }
  6083  
  6084  // ResetField resets all changes in the mutation for the field with the given name.
  6085  // It returns an error if the field is not defined in the schema.
  6086  func (m *RoleMutation) ResetField(name string) error {
  6087  	switch name {
  6088  	case role.FieldCreatedAt:
  6089  		m.ResetCreatedAt()
  6090  		return nil
  6091  	case role.FieldUpdatedAt:
  6092  		m.ResetUpdatedAt()
  6093  		return nil
  6094  	case role.FieldDeletedAt:
  6095  		m.ResetDeletedAt()
  6096  		return nil
  6097  	case role.FieldName:
  6098  		m.ResetName()
  6099  		return nil
  6100  	case role.FieldDescription:
  6101  		m.ResetDescription()
  6102  		return nil
  6103  	case role.FieldRoot:
  6104  		m.ResetRoot()
  6105  		return nil
  6106  	}
  6107  	return fmt.Errorf("unknown Role field %s", name)
  6108  }
  6109  
  6110  // AddedEdges returns all edge names that were set/added in this mutation.
  6111  func (m *RoleMutation) AddedEdges() []string {
  6112  	edges := make([]string, 0, 2)
  6113  	if m.permissions != nil {
  6114  		edges = append(edges, role.EdgePermissions)
  6115  	}
  6116  	if m.users != nil {
  6117  		edges = append(edges, role.EdgeUsers)
  6118  	}
  6119  	return edges
  6120  }
  6121  
  6122  // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  6123  // name in this mutation.
  6124  func (m *RoleMutation) AddedIDs(name string) []ent.Value {
  6125  	switch name {
  6126  	case role.EdgePermissions:
  6127  		ids := make([]ent.Value, 0, len(m.permissions))
  6128  		for id := range m.permissions {
  6129  			ids = append(ids, id)
  6130  		}
  6131  		return ids
  6132  	case role.EdgeUsers:
  6133  		ids := make([]ent.Value, 0, len(m.users))
  6134  		for id := range m.users {
  6135  			ids = append(ids, id)
  6136  		}
  6137  		return ids
  6138  	}
  6139  	return nil
  6140  }
  6141  
  6142  // RemovedEdges returns all edge names that were removed in this mutation.
  6143  func (m *RoleMutation) RemovedEdges() []string {
  6144  	edges := make([]string, 0, 2)
  6145  	if m.removedpermissions != nil {
  6146  		edges = append(edges, role.EdgePermissions)
  6147  	}
  6148  	if m.removedusers != nil {
  6149  		edges = append(edges, role.EdgeUsers)
  6150  	}
  6151  	return edges
  6152  }
  6153  
  6154  // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  6155  // the given name in this mutation.
  6156  func (m *RoleMutation) RemovedIDs(name string) []ent.Value {
  6157  	switch name {
  6158  	case role.EdgePermissions:
  6159  		ids := make([]ent.Value, 0, len(m.removedpermissions))
  6160  		for id := range m.removedpermissions {
  6161  			ids = append(ids, id)
  6162  		}
  6163  		return ids
  6164  	case role.EdgeUsers:
  6165  		ids := make([]ent.Value, 0, len(m.removedusers))
  6166  		for id := range m.removedusers {
  6167  			ids = append(ids, id)
  6168  		}
  6169  		return ids
  6170  	}
  6171  	return nil
  6172  }
  6173  
  6174  // ClearedEdges returns all edge names that were cleared in this mutation.
  6175  func (m *RoleMutation) ClearedEdges() []string {
  6176  	edges := make([]string, 0, 2)
  6177  	if m.clearedpermissions {
  6178  		edges = append(edges, role.EdgePermissions)
  6179  	}
  6180  	if m.clearedusers {
  6181  		edges = append(edges, role.EdgeUsers)
  6182  	}
  6183  	return edges
  6184  }
  6185  
  6186  // EdgeCleared returns a boolean which indicates if the edge with the given name
  6187  // was cleared in this mutation.
  6188  func (m *RoleMutation) EdgeCleared(name string) bool {
  6189  	switch name {
  6190  	case role.EdgePermissions:
  6191  		return m.clearedpermissions
  6192  	case role.EdgeUsers:
  6193  		return m.clearedusers
  6194  	}
  6195  	return false
  6196  }
  6197  
  6198  // ClearEdge clears the value of the edge with the given name. It returns an error
  6199  // if that edge is not defined in the schema.
  6200  func (m *RoleMutation) ClearEdge(name string) error {
  6201  	switch name {
  6202  	}
  6203  	return fmt.Errorf("unknown Role unique edge %s", name)
  6204  }
  6205  
  6206  // ResetEdge resets all changes to the edge with the given name in this mutation.
  6207  // It returns an error if the edge is not defined in the schema.
  6208  func (m *RoleMutation) ResetEdge(name string) error {
  6209  	switch name {
  6210  	case role.EdgePermissions:
  6211  		m.ResetPermissions()
  6212  		return nil
  6213  	case role.EdgeUsers:
  6214  		m.ResetUsers()
  6215  		return nil
  6216  	}
  6217  	return fmt.Errorf("unknown Role edge %s", name)
  6218  }
  6219  
  6220  // SettingMutation represents an operation that mutates the Setting nodes in the graph.
  6221  type SettingMutation struct {
  6222  	config
  6223  	op            Op
  6224  	typ           string
  6225  	id            *int
  6226  	created_at    *time.Time
  6227  	updated_at    *time.Time
  6228  	deleted_at    *time.Time
  6229  	name          *string
  6230  	value         *string
  6231  	_type         *string
  6232  	clearedFields map[string]struct{}
  6233  	done          bool
  6234  	oldValue      func(context.Context) (*Setting, error)
  6235  	predicates    []predicate.Setting
  6236  }
  6237  
  6238  var _ ent.Mutation = (*SettingMutation)(nil)
  6239  
  6240  // settingOption allows management of the mutation configuration using functional options.
  6241  type settingOption func(*SettingMutation)
  6242  
  6243  // newSettingMutation creates new mutation for the Setting entity.
  6244  func newSettingMutation(c config, op Op, opts ...settingOption) *SettingMutation {
  6245  	m := &SettingMutation{
  6246  		config:        c,
  6247  		op:            op,
  6248  		typ:           TypeSetting,
  6249  		clearedFields: make(map[string]struct{}),
  6250  	}
  6251  	for _, opt := range opts {
  6252  		opt(m)
  6253  	}
  6254  	return m
  6255  }
  6256  
  6257  // withSettingID sets the ID field of the mutation.
  6258  func withSettingID(id int) settingOption {
  6259  	return func(m *SettingMutation) {
  6260  		var (
  6261  			err   error
  6262  			once  sync.Once
  6263  			value *Setting
  6264  		)
  6265  		m.oldValue = func(ctx context.Context) (*Setting, error) {
  6266  			once.Do(func() {
  6267  				if m.done {
  6268  					err = errors.New("querying old values post mutation is not allowed")
  6269  				} else {
  6270  					value, err = m.Client().Setting.Get(ctx, id)
  6271  				}
  6272  			})
  6273  			return value, err
  6274  		}
  6275  		m.id = &id
  6276  	}
  6277  }
  6278  
  6279  // withSetting sets the old Setting of the mutation.
  6280  func withSetting(node *Setting) settingOption {
  6281  	return func(m *SettingMutation) {
  6282  		m.oldValue = func(context.Context) (*Setting, error) {
  6283  			return node, nil
  6284  		}
  6285  		m.id = &node.ID
  6286  	}
  6287  }
  6288  
  6289  // Client returns a new `ent.Client` from the mutation. If the mutation was
  6290  // executed in a transaction (ent.Tx), a transactional client is returned.
  6291  func (m SettingMutation) Client() *Client {
  6292  	client := &Client{config: m.config}
  6293  	client.init()
  6294  	return client
  6295  }
  6296  
  6297  // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  6298  // it returns an error otherwise.
  6299  func (m SettingMutation) Tx() (*Tx, error) {
  6300  	if _, ok := m.driver.(*txDriver); !ok {
  6301  		return nil, errors.New("ent: mutation is not running in a transaction")
  6302  	}
  6303  	tx := &Tx{config: m.config}
  6304  	tx.init()
  6305  	return tx, nil
  6306  }
  6307  
  6308  // ID returns the ID value in the mutation. Note that the ID is only available
  6309  // if it was provided to the builder or after it was returned from the database.
  6310  func (m *SettingMutation) ID() (id int, exists bool) {
  6311  	if m.id == nil {
  6312  		return
  6313  	}
  6314  	return *m.id, true
  6315  }
  6316  
  6317  // IDs queries the database and returns the entity ids that match the mutation's predicate.
  6318  // That means, if the mutation is applied within a transaction with an isolation level such
  6319  // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  6320  // or updated by the mutation.
  6321  func (m *SettingMutation) IDs(ctx context.Context) ([]int, error) {
  6322  	switch {
  6323  	case m.op.Is(OpUpdateOne | OpDeleteOne):
  6324  		id, exists := m.ID()
  6325  		if exists {
  6326  			return []int{id}, nil
  6327  		}
  6328  		fallthrough
  6329  	case m.op.Is(OpUpdate | OpDelete):
  6330  		return m.Client().Setting.Query().Where(m.predicates...).IDs(ctx)
  6331  	default:
  6332  		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  6333  	}
  6334  }
  6335  
  6336  // SetCreatedAt sets the "created_at" field.
  6337  func (m *SettingMutation) SetCreatedAt(t time.Time) {
  6338  	m.created_at = &t
  6339  }
  6340  
  6341  // CreatedAt returns the value of the "created_at" field in the mutation.
  6342  func (m *SettingMutation) CreatedAt() (r time.Time, exists bool) {
  6343  	v := m.created_at
  6344  	if v == nil {
  6345  		return
  6346  	}
  6347  	return *v, true
  6348  }
  6349  
  6350  // OldCreatedAt returns the old "created_at" field's value of the Setting entity.
  6351  // If the Setting object wasn't provided to the builder, the object is fetched from the database.
  6352  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  6353  func (m *SettingMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  6354  	if !m.op.Is(OpUpdateOne) {
  6355  		return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  6356  	}
  6357  	if m.id == nil || m.oldValue == nil {
  6358  		return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  6359  	}
  6360  	oldValue, err := m.oldValue(ctx)
  6361  	if err != nil {
  6362  		return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  6363  	}
  6364  	return oldValue.CreatedAt, nil
  6365  }
  6366  
  6367  // ResetCreatedAt resets all changes to the "created_at" field.
  6368  func (m *SettingMutation) ResetCreatedAt() {
  6369  	m.created_at = nil
  6370  }
  6371  
  6372  // SetUpdatedAt sets the "updated_at" field.
  6373  func (m *SettingMutation) SetUpdatedAt(t time.Time) {
  6374  	m.updated_at = &t
  6375  }
  6376  
  6377  // UpdatedAt returns the value of the "updated_at" field in the mutation.
  6378  func (m *SettingMutation) UpdatedAt() (r time.Time, exists bool) {
  6379  	v := m.updated_at
  6380  	if v == nil {
  6381  		return
  6382  	}
  6383  	return *v, true
  6384  }
  6385  
  6386  // OldUpdatedAt returns the old "updated_at" field's value of the Setting entity.
  6387  // If the Setting object wasn't provided to the builder, the object is fetched from the database.
  6388  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  6389  func (m *SettingMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  6390  	if !m.op.Is(OpUpdateOne) {
  6391  		return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  6392  	}
  6393  	if m.id == nil || m.oldValue == nil {
  6394  		return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  6395  	}
  6396  	oldValue, err := m.oldValue(ctx)
  6397  	if err != nil {
  6398  		return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  6399  	}
  6400  	return oldValue.UpdatedAt, nil
  6401  }
  6402  
  6403  // ResetUpdatedAt resets all changes to the "updated_at" field.
  6404  func (m *SettingMutation) ResetUpdatedAt() {
  6405  	m.updated_at = nil
  6406  }
  6407  
  6408  // SetDeletedAt sets the "deleted_at" field.
  6409  func (m *SettingMutation) SetDeletedAt(t time.Time) {
  6410  	m.deleted_at = &t
  6411  }
  6412  
  6413  // DeletedAt returns the value of the "deleted_at" field in the mutation.
  6414  func (m *SettingMutation) DeletedAt() (r time.Time, exists bool) {
  6415  	v := m.deleted_at
  6416  	if v == nil {
  6417  		return
  6418  	}
  6419  	return *v, true
  6420  }
  6421  
  6422  // OldDeletedAt returns the old "deleted_at" field's value of the Setting entity.
  6423  // If the Setting object wasn't provided to the builder, the object is fetched from the database.
  6424  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  6425  func (m *SettingMutation) OldDeletedAt(ctx context.Context) (v time.Time, err error) {
  6426  	if !m.op.Is(OpUpdateOne) {
  6427  		return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
  6428  	}
  6429  	if m.id == nil || m.oldValue == nil {
  6430  		return v, errors.New("OldDeletedAt requires an ID field in the mutation")
  6431  	}
  6432  	oldValue, err := m.oldValue(ctx)
  6433  	if err != nil {
  6434  		return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
  6435  	}
  6436  	return oldValue.DeletedAt, nil
  6437  }
  6438  
  6439  // ClearDeletedAt clears the value of the "deleted_at" field.
  6440  func (m *SettingMutation) ClearDeletedAt() {
  6441  	m.deleted_at = nil
  6442  	m.clearedFields[setting.FieldDeletedAt] = struct{}{}
  6443  }
  6444  
  6445  // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
  6446  func (m *SettingMutation) DeletedAtCleared() bool {
  6447  	_, ok := m.clearedFields[setting.FieldDeletedAt]
  6448  	return ok
  6449  }
  6450  
  6451  // ResetDeletedAt resets all changes to the "deleted_at" field.
  6452  func (m *SettingMutation) ResetDeletedAt() {
  6453  	m.deleted_at = nil
  6454  	delete(m.clearedFields, setting.FieldDeletedAt)
  6455  }
  6456  
  6457  // SetName sets the "name" field.
  6458  func (m *SettingMutation) SetName(s string) {
  6459  	m.name = &s
  6460  }
  6461  
  6462  // Name returns the value of the "name" field in the mutation.
  6463  func (m *SettingMutation) Name() (r string, exists bool) {
  6464  	v := m.name
  6465  	if v == nil {
  6466  		return
  6467  	}
  6468  	return *v, true
  6469  }
  6470  
  6471  // OldName returns the old "name" field's value of the Setting entity.
  6472  // If the Setting object wasn't provided to the builder, the object is fetched from the database.
  6473  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  6474  func (m *SettingMutation) OldName(ctx context.Context) (v string, err error) {
  6475  	if !m.op.Is(OpUpdateOne) {
  6476  		return v, errors.New("OldName is only allowed on UpdateOne operations")
  6477  	}
  6478  	if m.id == nil || m.oldValue == nil {
  6479  		return v, errors.New("OldName requires an ID field in the mutation")
  6480  	}
  6481  	oldValue, err := m.oldValue(ctx)
  6482  	if err != nil {
  6483  		return v, fmt.Errorf("querying old value for OldName: %w", err)
  6484  	}
  6485  	return oldValue.Name, nil
  6486  }
  6487  
  6488  // ResetName resets all changes to the "name" field.
  6489  func (m *SettingMutation) ResetName() {
  6490  	m.name = nil
  6491  }
  6492  
  6493  // SetValue sets the "value" field.
  6494  func (m *SettingMutation) SetValue(s string) {
  6495  	m.value = &s
  6496  }
  6497  
  6498  // Value returns the value of the "value" field in the mutation.
  6499  func (m *SettingMutation) Value() (r string, exists bool) {
  6500  	v := m.value
  6501  	if v == nil {
  6502  		return
  6503  	}
  6504  	return *v, true
  6505  }
  6506  
  6507  // OldValue returns the old "value" field's value of the Setting entity.
  6508  // If the Setting object wasn't provided to the builder, the object is fetched from the database.
  6509  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  6510  func (m *SettingMutation) OldValue(ctx context.Context) (v string, err error) {
  6511  	if !m.op.Is(OpUpdateOne) {
  6512  		return v, errors.New("OldValue is only allowed on UpdateOne operations")
  6513  	}
  6514  	if m.id == nil || m.oldValue == nil {
  6515  		return v, errors.New("OldValue requires an ID field in the mutation")
  6516  	}
  6517  	oldValue, err := m.oldValue(ctx)
  6518  	if err != nil {
  6519  		return v, fmt.Errorf("querying old value for OldValue: %w", err)
  6520  	}
  6521  	return oldValue.Value, nil
  6522  }
  6523  
  6524  // ClearValue clears the value of the "value" field.
  6525  func (m *SettingMutation) ClearValue() {
  6526  	m.value = nil
  6527  	m.clearedFields[setting.FieldValue] = struct{}{}
  6528  }
  6529  
  6530  // ValueCleared returns if the "value" field was cleared in this mutation.
  6531  func (m *SettingMutation) ValueCleared() bool {
  6532  	_, ok := m.clearedFields[setting.FieldValue]
  6533  	return ok
  6534  }
  6535  
  6536  // ResetValue resets all changes to the "value" field.
  6537  func (m *SettingMutation) ResetValue() {
  6538  	m.value = nil
  6539  	delete(m.clearedFields, setting.FieldValue)
  6540  }
  6541  
  6542  // SetType sets the "type" field.
  6543  func (m *SettingMutation) SetType(s string) {
  6544  	m._type = &s
  6545  }
  6546  
  6547  // GetType returns the value of the "type" field in the mutation.
  6548  func (m *SettingMutation) GetType() (r string, exists bool) {
  6549  	v := m._type
  6550  	if v == nil {
  6551  		return
  6552  	}
  6553  	return *v, true
  6554  }
  6555  
  6556  // OldType returns the old "type" field's value of the Setting entity.
  6557  // If the Setting object wasn't provided to the builder, the object is fetched from the database.
  6558  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  6559  func (m *SettingMutation) OldType(ctx context.Context) (v string, err error) {
  6560  	if !m.op.Is(OpUpdateOne) {
  6561  		return v, errors.New("OldType is only allowed on UpdateOne operations")
  6562  	}
  6563  	if m.id == nil || m.oldValue == nil {
  6564  		return v, errors.New("OldType requires an ID field in the mutation")
  6565  	}
  6566  	oldValue, err := m.oldValue(ctx)
  6567  	if err != nil {
  6568  		return v, fmt.Errorf("querying old value for OldType: %w", err)
  6569  	}
  6570  	return oldValue.Type, nil
  6571  }
  6572  
  6573  // ClearType clears the value of the "type" field.
  6574  func (m *SettingMutation) ClearType() {
  6575  	m._type = nil
  6576  	m.clearedFields[setting.FieldType] = struct{}{}
  6577  }
  6578  
  6579  // TypeCleared returns if the "type" field was cleared in this mutation.
  6580  func (m *SettingMutation) TypeCleared() bool {
  6581  	_, ok := m.clearedFields[setting.FieldType]
  6582  	return ok
  6583  }
  6584  
  6585  // ResetType resets all changes to the "type" field.
  6586  func (m *SettingMutation) ResetType() {
  6587  	m._type = nil
  6588  	delete(m.clearedFields, setting.FieldType)
  6589  }
  6590  
  6591  // Where appends a list predicates to the SettingMutation builder.
  6592  func (m *SettingMutation) Where(ps ...predicate.Setting) {
  6593  	m.predicates = append(m.predicates, ps...)
  6594  }
  6595  
  6596  // Op returns the operation name.
  6597  func (m *SettingMutation) Op() Op {
  6598  	return m.op
  6599  }
  6600  
  6601  // Type returns the node type of this mutation (Setting).
  6602  func (m *SettingMutation) Type() string {
  6603  	return m.typ
  6604  }
  6605  
  6606  // Fields returns all fields that were changed during this mutation. Note that in
  6607  // order to get all numeric fields that were incremented/decremented, call
  6608  // AddedFields().
  6609  func (m *SettingMutation) Fields() []string {
  6610  	fields := make([]string, 0, 6)
  6611  	if m.created_at != nil {
  6612  		fields = append(fields, setting.FieldCreatedAt)
  6613  	}
  6614  	if m.updated_at != nil {
  6615  		fields = append(fields, setting.FieldUpdatedAt)
  6616  	}
  6617  	if m.deleted_at != nil {
  6618  		fields = append(fields, setting.FieldDeletedAt)
  6619  	}
  6620  	if m.name != nil {
  6621  		fields = append(fields, setting.FieldName)
  6622  	}
  6623  	if m.value != nil {
  6624  		fields = append(fields, setting.FieldValue)
  6625  	}
  6626  	if m._type != nil {
  6627  		fields = append(fields, setting.FieldType)
  6628  	}
  6629  	return fields
  6630  }
  6631  
  6632  // Field returns the value of a field with the given name. The second boolean
  6633  // return value indicates that this field was not set, or was not defined in the
  6634  // schema.
  6635  func (m *SettingMutation) Field(name string) (ent.Value, bool) {
  6636  	switch name {
  6637  	case setting.FieldCreatedAt:
  6638  		return m.CreatedAt()
  6639  	case setting.FieldUpdatedAt:
  6640  		return m.UpdatedAt()
  6641  	case setting.FieldDeletedAt:
  6642  		return m.DeletedAt()
  6643  	case setting.FieldName:
  6644  		return m.Name()
  6645  	case setting.FieldValue:
  6646  		return m.Value()
  6647  	case setting.FieldType:
  6648  		return m.GetType()
  6649  	}
  6650  	return nil, false
  6651  }
  6652  
  6653  // OldField returns the old value of the field from the database. An error is
  6654  // returned if the mutation operation is not UpdateOne, or the query to the
  6655  // database failed.
  6656  func (m *SettingMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  6657  	switch name {
  6658  	case setting.FieldCreatedAt:
  6659  		return m.OldCreatedAt(ctx)
  6660  	case setting.FieldUpdatedAt:
  6661  		return m.OldUpdatedAt(ctx)
  6662  	case setting.FieldDeletedAt:
  6663  		return m.OldDeletedAt(ctx)
  6664  	case setting.FieldName:
  6665  		return m.OldName(ctx)
  6666  	case setting.FieldValue:
  6667  		return m.OldValue(ctx)
  6668  	case setting.FieldType:
  6669  		return m.OldType(ctx)
  6670  	}
  6671  	return nil, fmt.Errorf("unknown Setting field %s", name)
  6672  }
  6673  
  6674  // SetField sets the value of a field with the given name. It returns an error if
  6675  // the field is not defined in the schema, or if the type mismatched the field
  6676  // type.
  6677  func (m *SettingMutation) SetField(name string, value ent.Value) error {
  6678  	switch name {
  6679  	case setting.FieldCreatedAt:
  6680  		v, ok := value.(time.Time)
  6681  		if !ok {
  6682  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  6683  		}
  6684  		m.SetCreatedAt(v)
  6685  		return nil
  6686  	case setting.FieldUpdatedAt:
  6687  		v, ok := value.(time.Time)
  6688  		if !ok {
  6689  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  6690  		}
  6691  		m.SetUpdatedAt(v)
  6692  		return nil
  6693  	case setting.FieldDeletedAt:
  6694  		v, ok := value.(time.Time)
  6695  		if !ok {
  6696  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  6697  		}
  6698  		m.SetDeletedAt(v)
  6699  		return nil
  6700  	case setting.FieldName:
  6701  		v, ok := value.(string)
  6702  		if !ok {
  6703  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  6704  		}
  6705  		m.SetName(v)
  6706  		return nil
  6707  	case setting.FieldValue:
  6708  		v, ok := value.(string)
  6709  		if !ok {
  6710  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  6711  		}
  6712  		m.SetValue(v)
  6713  		return nil
  6714  	case setting.FieldType:
  6715  		v, ok := value.(string)
  6716  		if !ok {
  6717  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  6718  		}
  6719  		m.SetType(v)
  6720  		return nil
  6721  	}
  6722  	return fmt.Errorf("unknown Setting field %s", name)
  6723  }
  6724  
  6725  // AddedFields returns all numeric fields that were incremented/decremented during
  6726  // this mutation.
  6727  func (m *SettingMutation) AddedFields() []string {
  6728  	return nil
  6729  }
  6730  
  6731  // AddedField returns the numeric value that was incremented/decremented on a field
  6732  // with the given name. The second boolean return value indicates that this field
  6733  // was not set, or was not defined in the schema.
  6734  func (m *SettingMutation) AddedField(name string) (ent.Value, bool) {
  6735  	return nil, false
  6736  }
  6737  
  6738  // AddField adds the value to the field with the given name. It returns an error if
  6739  // the field is not defined in the schema, or if the type mismatched the field
  6740  // type.
  6741  func (m *SettingMutation) AddField(name string, value ent.Value) error {
  6742  	switch name {
  6743  	}
  6744  	return fmt.Errorf("unknown Setting numeric field %s", name)
  6745  }
  6746  
  6747  // ClearedFields returns all nullable fields that were cleared during this
  6748  // mutation.
  6749  func (m *SettingMutation) ClearedFields() []string {
  6750  	var fields []string
  6751  	if m.FieldCleared(setting.FieldDeletedAt) {
  6752  		fields = append(fields, setting.FieldDeletedAt)
  6753  	}
  6754  	if m.FieldCleared(setting.FieldValue) {
  6755  		fields = append(fields, setting.FieldValue)
  6756  	}
  6757  	if m.FieldCleared(setting.FieldType) {
  6758  		fields = append(fields, setting.FieldType)
  6759  	}
  6760  	return fields
  6761  }
  6762  
  6763  // FieldCleared returns a boolean indicating if a field with the given name was
  6764  // cleared in this mutation.
  6765  func (m *SettingMutation) FieldCleared(name string) bool {
  6766  	_, ok := m.clearedFields[name]
  6767  	return ok
  6768  }
  6769  
  6770  // ClearField clears the value of the field with the given name. It returns an
  6771  // error if the field is not defined in the schema.
  6772  func (m *SettingMutation) ClearField(name string) error {
  6773  	switch name {
  6774  	case setting.FieldDeletedAt:
  6775  		m.ClearDeletedAt()
  6776  		return nil
  6777  	case setting.FieldValue:
  6778  		m.ClearValue()
  6779  		return nil
  6780  	case setting.FieldType:
  6781  		m.ClearType()
  6782  		return nil
  6783  	}
  6784  	return fmt.Errorf("unknown Setting nullable field %s", name)
  6785  }
  6786  
  6787  // ResetField resets all changes in the mutation for the field with the given name.
  6788  // It returns an error if the field is not defined in the schema.
  6789  func (m *SettingMutation) ResetField(name string) error {
  6790  	switch name {
  6791  	case setting.FieldCreatedAt:
  6792  		m.ResetCreatedAt()
  6793  		return nil
  6794  	case setting.FieldUpdatedAt:
  6795  		m.ResetUpdatedAt()
  6796  		return nil
  6797  	case setting.FieldDeletedAt:
  6798  		m.ResetDeletedAt()
  6799  		return nil
  6800  	case setting.FieldName:
  6801  		m.ResetName()
  6802  		return nil
  6803  	case setting.FieldValue:
  6804  		m.ResetValue()
  6805  		return nil
  6806  	case setting.FieldType:
  6807  		m.ResetType()
  6808  		return nil
  6809  	}
  6810  	return fmt.Errorf("unknown Setting field %s", name)
  6811  }
  6812  
  6813  // AddedEdges returns all edge names that were set/added in this mutation.
  6814  func (m *SettingMutation) AddedEdges() []string {
  6815  	edges := make([]string, 0, 0)
  6816  	return edges
  6817  }
  6818  
  6819  // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  6820  // name in this mutation.
  6821  func (m *SettingMutation) AddedIDs(name string) []ent.Value {
  6822  	return nil
  6823  }
  6824  
  6825  // RemovedEdges returns all edge names that were removed in this mutation.
  6826  func (m *SettingMutation) RemovedEdges() []string {
  6827  	edges := make([]string, 0, 0)
  6828  	return edges
  6829  }
  6830  
  6831  // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  6832  // the given name in this mutation.
  6833  func (m *SettingMutation) RemovedIDs(name string) []ent.Value {
  6834  	return nil
  6835  }
  6836  
  6837  // ClearedEdges returns all edge names that were cleared in this mutation.
  6838  func (m *SettingMutation) ClearedEdges() []string {
  6839  	edges := make([]string, 0, 0)
  6840  	return edges
  6841  }
  6842  
  6843  // EdgeCleared returns a boolean which indicates if the edge with the given name
  6844  // was cleared in this mutation.
  6845  func (m *SettingMutation) EdgeCleared(name string) bool {
  6846  	return false
  6847  }
  6848  
  6849  // ClearEdge clears the value of the edge with the given name. It returns an error
  6850  // if that edge is not defined in the schema.
  6851  func (m *SettingMutation) ClearEdge(name string) error {
  6852  	return fmt.Errorf("unknown Setting unique edge %s", name)
  6853  }
  6854  
  6855  // ResetEdge resets all changes to the edge with the given name in this mutation.
  6856  // It returns an error if the edge is not defined in the schema.
  6857  func (m *SettingMutation) ResetEdge(name string) error {
  6858  	return fmt.Errorf("unknown Setting edge %s", name)
  6859  }
  6860  
  6861  // TopicMutation represents an operation that mutates the Topic nodes in the graph.
  6862  type TopicMutation struct {
  6863  	config
  6864  	op              Op
  6865  	typ             string
  6866  	id              *int
  6867  	created_at      *time.Time
  6868  	updated_at      *time.Time
  6869  	deleted_at      *time.Time
  6870  	name            *string
  6871  	slug            *string
  6872  	description     *string
  6873  	content         *string
  6874  	content_html    *string
  6875  	clearedFields   map[string]struct{}
  6876  	posts           map[int]struct{}
  6877  	removedposts    map[int]struct{}
  6878  	clearedposts    bool
  6879  	children        map[int]struct{}
  6880  	removedchildren map[int]struct{}
  6881  	clearedchildren bool
  6882  	parent          *int
  6883  	clearedparent   bool
  6884  	done            bool
  6885  	oldValue        func(context.Context) (*Topic, error)
  6886  	predicates      []predicate.Topic
  6887  }
  6888  
  6889  var _ ent.Mutation = (*TopicMutation)(nil)
  6890  
  6891  // topicOption allows management of the mutation configuration using functional options.
  6892  type topicOption func(*TopicMutation)
  6893  
  6894  // newTopicMutation creates new mutation for the Topic entity.
  6895  func newTopicMutation(c config, op Op, opts ...topicOption) *TopicMutation {
  6896  	m := &TopicMutation{
  6897  		config:        c,
  6898  		op:            op,
  6899  		typ:           TypeTopic,
  6900  		clearedFields: make(map[string]struct{}),
  6901  	}
  6902  	for _, opt := range opts {
  6903  		opt(m)
  6904  	}
  6905  	return m
  6906  }
  6907  
  6908  // withTopicID sets the ID field of the mutation.
  6909  func withTopicID(id int) topicOption {
  6910  	return func(m *TopicMutation) {
  6911  		var (
  6912  			err   error
  6913  			once  sync.Once
  6914  			value *Topic
  6915  		)
  6916  		m.oldValue = func(ctx context.Context) (*Topic, error) {
  6917  			once.Do(func() {
  6918  				if m.done {
  6919  					err = errors.New("querying old values post mutation is not allowed")
  6920  				} else {
  6921  					value, err = m.Client().Topic.Get(ctx, id)
  6922  				}
  6923  			})
  6924  			return value, err
  6925  		}
  6926  		m.id = &id
  6927  	}
  6928  }
  6929  
  6930  // withTopic sets the old Topic of the mutation.
  6931  func withTopic(node *Topic) topicOption {
  6932  	return func(m *TopicMutation) {
  6933  		m.oldValue = func(context.Context) (*Topic, error) {
  6934  			return node, nil
  6935  		}
  6936  		m.id = &node.ID
  6937  	}
  6938  }
  6939  
  6940  // Client returns a new `ent.Client` from the mutation. If the mutation was
  6941  // executed in a transaction (ent.Tx), a transactional client is returned.
  6942  func (m TopicMutation) Client() *Client {
  6943  	client := &Client{config: m.config}
  6944  	client.init()
  6945  	return client
  6946  }
  6947  
  6948  // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  6949  // it returns an error otherwise.
  6950  func (m TopicMutation) Tx() (*Tx, error) {
  6951  	if _, ok := m.driver.(*txDriver); !ok {
  6952  		return nil, errors.New("ent: mutation is not running in a transaction")
  6953  	}
  6954  	tx := &Tx{config: m.config}
  6955  	tx.init()
  6956  	return tx, nil
  6957  }
  6958  
  6959  // ID returns the ID value in the mutation. Note that the ID is only available
  6960  // if it was provided to the builder or after it was returned from the database.
  6961  func (m *TopicMutation) ID() (id int, exists bool) {
  6962  	if m.id == nil {
  6963  		return
  6964  	}
  6965  	return *m.id, true
  6966  }
  6967  
  6968  // IDs queries the database and returns the entity ids that match the mutation's predicate.
  6969  // That means, if the mutation is applied within a transaction with an isolation level such
  6970  // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  6971  // or updated by the mutation.
  6972  func (m *TopicMutation) IDs(ctx context.Context) ([]int, error) {
  6973  	switch {
  6974  	case m.op.Is(OpUpdateOne | OpDeleteOne):
  6975  		id, exists := m.ID()
  6976  		if exists {
  6977  			return []int{id}, nil
  6978  		}
  6979  		fallthrough
  6980  	case m.op.Is(OpUpdate | OpDelete):
  6981  		return m.Client().Topic.Query().Where(m.predicates...).IDs(ctx)
  6982  	default:
  6983  		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  6984  	}
  6985  }
  6986  
  6987  // SetCreatedAt sets the "created_at" field.
  6988  func (m *TopicMutation) SetCreatedAt(t time.Time) {
  6989  	m.created_at = &t
  6990  }
  6991  
  6992  // CreatedAt returns the value of the "created_at" field in the mutation.
  6993  func (m *TopicMutation) CreatedAt() (r time.Time, exists bool) {
  6994  	v := m.created_at
  6995  	if v == nil {
  6996  		return
  6997  	}
  6998  	return *v, true
  6999  }
  7000  
  7001  // OldCreatedAt returns the old "created_at" field's value of the Topic entity.
  7002  // If the Topic object wasn't provided to the builder, the object is fetched from the database.
  7003  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  7004  func (m *TopicMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  7005  	if !m.op.Is(OpUpdateOne) {
  7006  		return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  7007  	}
  7008  	if m.id == nil || m.oldValue == nil {
  7009  		return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  7010  	}
  7011  	oldValue, err := m.oldValue(ctx)
  7012  	if err != nil {
  7013  		return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  7014  	}
  7015  	return oldValue.CreatedAt, nil
  7016  }
  7017  
  7018  // ResetCreatedAt resets all changes to the "created_at" field.
  7019  func (m *TopicMutation) ResetCreatedAt() {
  7020  	m.created_at = nil
  7021  }
  7022  
  7023  // SetUpdatedAt sets the "updated_at" field.
  7024  func (m *TopicMutation) SetUpdatedAt(t time.Time) {
  7025  	m.updated_at = &t
  7026  }
  7027  
  7028  // UpdatedAt returns the value of the "updated_at" field in the mutation.
  7029  func (m *TopicMutation) UpdatedAt() (r time.Time, exists bool) {
  7030  	v := m.updated_at
  7031  	if v == nil {
  7032  		return
  7033  	}
  7034  	return *v, true
  7035  }
  7036  
  7037  // OldUpdatedAt returns the old "updated_at" field's value of the Topic entity.
  7038  // If the Topic object wasn't provided to the builder, the object is fetched from the database.
  7039  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  7040  func (m *TopicMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  7041  	if !m.op.Is(OpUpdateOne) {
  7042  		return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  7043  	}
  7044  	if m.id == nil || m.oldValue == nil {
  7045  		return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  7046  	}
  7047  	oldValue, err := m.oldValue(ctx)
  7048  	if err != nil {
  7049  		return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  7050  	}
  7051  	return oldValue.UpdatedAt, nil
  7052  }
  7053  
  7054  // ResetUpdatedAt resets all changes to the "updated_at" field.
  7055  func (m *TopicMutation) ResetUpdatedAt() {
  7056  	m.updated_at = nil
  7057  }
  7058  
  7059  // SetDeletedAt sets the "deleted_at" field.
  7060  func (m *TopicMutation) SetDeletedAt(t time.Time) {
  7061  	m.deleted_at = &t
  7062  }
  7063  
  7064  // DeletedAt returns the value of the "deleted_at" field in the mutation.
  7065  func (m *TopicMutation) DeletedAt() (r time.Time, exists bool) {
  7066  	v := m.deleted_at
  7067  	if v == nil {
  7068  		return
  7069  	}
  7070  	return *v, true
  7071  }
  7072  
  7073  // OldDeletedAt returns the old "deleted_at" field's value of the Topic entity.
  7074  // If the Topic object wasn't provided to the builder, the object is fetched from the database.
  7075  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  7076  func (m *TopicMutation) OldDeletedAt(ctx context.Context) (v time.Time, err error) {
  7077  	if !m.op.Is(OpUpdateOne) {
  7078  		return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
  7079  	}
  7080  	if m.id == nil || m.oldValue == nil {
  7081  		return v, errors.New("OldDeletedAt requires an ID field in the mutation")
  7082  	}
  7083  	oldValue, err := m.oldValue(ctx)
  7084  	if err != nil {
  7085  		return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
  7086  	}
  7087  	return oldValue.DeletedAt, nil
  7088  }
  7089  
  7090  // ClearDeletedAt clears the value of the "deleted_at" field.
  7091  func (m *TopicMutation) ClearDeletedAt() {
  7092  	m.deleted_at = nil
  7093  	m.clearedFields[topic.FieldDeletedAt] = struct{}{}
  7094  }
  7095  
  7096  // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
  7097  func (m *TopicMutation) DeletedAtCleared() bool {
  7098  	_, ok := m.clearedFields[topic.FieldDeletedAt]
  7099  	return ok
  7100  }
  7101  
  7102  // ResetDeletedAt resets all changes to the "deleted_at" field.
  7103  func (m *TopicMutation) ResetDeletedAt() {
  7104  	m.deleted_at = nil
  7105  	delete(m.clearedFields, topic.FieldDeletedAt)
  7106  }
  7107  
  7108  // SetName sets the "name" field.
  7109  func (m *TopicMutation) SetName(s string) {
  7110  	m.name = &s
  7111  }
  7112  
  7113  // Name returns the value of the "name" field in the mutation.
  7114  func (m *TopicMutation) Name() (r string, exists bool) {
  7115  	v := m.name
  7116  	if v == nil {
  7117  		return
  7118  	}
  7119  	return *v, true
  7120  }
  7121  
  7122  // OldName returns the old "name" field's value of the Topic entity.
  7123  // If the Topic object wasn't provided to the builder, the object is fetched from the database.
  7124  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  7125  func (m *TopicMutation) OldName(ctx context.Context) (v string, err error) {
  7126  	if !m.op.Is(OpUpdateOne) {
  7127  		return v, errors.New("OldName is only allowed on UpdateOne operations")
  7128  	}
  7129  	if m.id == nil || m.oldValue == nil {
  7130  		return v, errors.New("OldName requires an ID field in the mutation")
  7131  	}
  7132  	oldValue, err := m.oldValue(ctx)
  7133  	if err != nil {
  7134  		return v, fmt.Errorf("querying old value for OldName: %w", err)
  7135  	}
  7136  	return oldValue.Name, nil
  7137  }
  7138  
  7139  // ResetName resets all changes to the "name" field.
  7140  func (m *TopicMutation) ResetName() {
  7141  	m.name = nil
  7142  }
  7143  
  7144  // SetSlug sets the "slug" field.
  7145  func (m *TopicMutation) SetSlug(s string) {
  7146  	m.slug = &s
  7147  }
  7148  
  7149  // Slug returns the value of the "slug" field in the mutation.
  7150  func (m *TopicMutation) Slug() (r string, exists bool) {
  7151  	v := m.slug
  7152  	if v == nil {
  7153  		return
  7154  	}
  7155  	return *v, true
  7156  }
  7157  
  7158  // OldSlug returns the old "slug" field's value of the Topic entity.
  7159  // If the Topic object wasn't provided to the builder, the object is fetched from the database.
  7160  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  7161  func (m *TopicMutation) OldSlug(ctx context.Context) (v string, err error) {
  7162  	if !m.op.Is(OpUpdateOne) {
  7163  		return v, errors.New("OldSlug is only allowed on UpdateOne operations")
  7164  	}
  7165  	if m.id == nil || m.oldValue == nil {
  7166  		return v, errors.New("OldSlug requires an ID field in the mutation")
  7167  	}
  7168  	oldValue, err := m.oldValue(ctx)
  7169  	if err != nil {
  7170  		return v, fmt.Errorf("querying old value for OldSlug: %w", err)
  7171  	}
  7172  	return oldValue.Slug, nil
  7173  }
  7174  
  7175  // ResetSlug resets all changes to the "slug" field.
  7176  func (m *TopicMutation) ResetSlug() {
  7177  	m.slug = nil
  7178  }
  7179  
  7180  // SetDescription sets the "description" field.
  7181  func (m *TopicMutation) SetDescription(s string) {
  7182  	m.description = &s
  7183  }
  7184  
  7185  // Description returns the value of the "description" field in the mutation.
  7186  func (m *TopicMutation) Description() (r string, exists bool) {
  7187  	v := m.description
  7188  	if v == nil {
  7189  		return
  7190  	}
  7191  	return *v, true
  7192  }
  7193  
  7194  // OldDescription returns the old "description" field's value of the Topic entity.
  7195  // If the Topic object wasn't provided to the builder, the object is fetched from the database.
  7196  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  7197  func (m *TopicMutation) OldDescription(ctx context.Context) (v string, err error) {
  7198  	if !m.op.Is(OpUpdateOne) {
  7199  		return v, errors.New("OldDescription is only allowed on UpdateOne operations")
  7200  	}
  7201  	if m.id == nil || m.oldValue == nil {
  7202  		return v, errors.New("OldDescription requires an ID field in the mutation")
  7203  	}
  7204  	oldValue, err := m.oldValue(ctx)
  7205  	if err != nil {
  7206  		return v, fmt.Errorf("querying old value for OldDescription: %w", err)
  7207  	}
  7208  	return oldValue.Description, nil
  7209  }
  7210  
  7211  // ClearDescription clears the value of the "description" field.
  7212  func (m *TopicMutation) ClearDescription() {
  7213  	m.description = nil
  7214  	m.clearedFields[topic.FieldDescription] = struct{}{}
  7215  }
  7216  
  7217  // DescriptionCleared returns if the "description" field was cleared in this mutation.
  7218  func (m *TopicMutation) DescriptionCleared() bool {
  7219  	_, ok := m.clearedFields[topic.FieldDescription]
  7220  	return ok
  7221  }
  7222  
  7223  // ResetDescription resets all changes to the "description" field.
  7224  func (m *TopicMutation) ResetDescription() {
  7225  	m.description = nil
  7226  	delete(m.clearedFields, topic.FieldDescription)
  7227  }
  7228  
  7229  // SetContent sets the "content" field.
  7230  func (m *TopicMutation) SetContent(s string) {
  7231  	m.content = &s
  7232  }
  7233  
  7234  // Content returns the value of the "content" field in the mutation.
  7235  func (m *TopicMutation) Content() (r string, exists bool) {
  7236  	v := m.content
  7237  	if v == nil {
  7238  		return
  7239  	}
  7240  	return *v, true
  7241  }
  7242  
  7243  // OldContent returns the old "content" field's value of the Topic entity.
  7244  // If the Topic object wasn't provided to the builder, the object is fetched from the database.
  7245  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  7246  func (m *TopicMutation) OldContent(ctx context.Context) (v string, err error) {
  7247  	if !m.op.Is(OpUpdateOne) {
  7248  		return v, errors.New("OldContent is only allowed on UpdateOne operations")
  7249  	}
  7250  	if m.id == nil || m.oldValue == nil {
  7251  		return v, errors.New("OldContent requires an ID field in the mutation")
  7252  	}
  7253  	oldValue, err := m.oldValue(ctx)
  7254  	if err != nil {
  7255  		return v, fmt.Errorf("querying old value for OldContent: %w", err)
  7256  	}
  7257  	return oldValue.Content, nil
  7258  }
  7259  
  7260  // ResetContent resets all changes to the "content" field.
  7261  func (m *TopicMutation) ResetContent() {
  7262  	m.content = nil
  7263  }
  7264  
  7265  // SetContentHTML sets the "content_html" field.
  7266  func (m *TopicMutation) SetContentHTML(s string) {
  7267  	m.content_html = &s
  7268  }
  7269  
  7270  // ContentHTML returns the value of the "content_html" field in the mutation.
  7271  func (m *TopicMutation) ContentHTML() (r string, exists bool) {
  7272  	v := m.content_html
  7273  	if v == nil {
  7274  		return
  7275  	}
  7276  	return *v, true
  7277  }
  7278  
  7279  // OldContentHTML returns the old "content_html" field's value of the Topic entity.
  7280  // If the Topic object wasn't provided to the builder, the object is fetched from the database.
  7281  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  7282  func (m *TopicMutation) OldContentHTML(ctx context.Context) (v string, err error) {
  7283  	if !m.op.Is(OpUpdateOne) {
  7284  		return v, errors.New("OldContentHTML is only allowed on UpdateOne operations")
  7285  	}
  7286  	if m.id == nil || m.oldValue == nil {
  7287  		return v, errors.New("OldContentHTML requires an ID field in the mutation")
  7288  	}
  7289  	oldValue, err := m.oldValue(ctx)
  7290  	if err != nil {
  7291  		return v, fmt.Errorf("querying old value for OldContentHTML: %w", err)
  7292  	}
  7293  	return oldValue.ContentHTML, nil
  7294  }
  7295  
  7296  // ResetContentHTML resets all changes to the "content_html" field.
  7297  func (m *TopicMutation) ResetContentHTML() {
  7298  	m.content_html = nil
  7299  }
  7300  
  7301  // SetParentID sets the "parent_id" field.
  7302  func (m *TopicMutation) SetParentID(i int) {
  7303  	m.parent = &i
  7304  }
  7305  
  7306  // ParentID returns the value of the "parent_id" field in the mutation.
  7307  func (m *TopicMutation) ParentID() (r int, exists bool) {
  7308  	v := m.parent
  7309  	if v == nil {
  7310  		return
  7311  	}
  7312  	return *v, true
  7313  }
  7314  
  7315  // OldParentID returns the old "parent_id" field's value of the Topic entity.
  7316  // If the Topic object wasn't provided to the builder, the object is fetched from the database.
  7317  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  7318  func (m *TopicMutation) OldParentID(ctx context.Context) (v int, err error) {
  7319  	if !m.op.Is(OpUpdateOne) {
  7320  		return v, errors.New("OldParentID is only allowed on UpdateOne operations")
  7321  	}
  7322  	if m.id == nil || m.oldValue == nil {
  7323  		return v, errors.New("OldParentID requires an ID field in the mutation")
  7324  	}
  7325  	oldValue, err := m.oldValue(ctx)
  7326  	if err != nil {
  7327  		return v, fmt.Errorf("querying old value for OldParentID: %w", err)
  7328  	}
  7329  	return oldValue.ParentID, nil
  7330  }
  7331  
  7332  // ClearParentID clears the value of the "parent_id" field.
  7333  func (m *TopicMutation) ClearParentID() {
  7334  	m.parent = nil
  7335  	m.clearedFields[topic.FieldParentID] = struct{}{}
  7336  }
  7337  
  7338  // ParentIDCleared returns if the "parent_id" field was cleared in this mutation.
  7339  func (m *TopicMutation) ParentIDCleared() bool {
  7340  	_, ok := m.clearedFields[topic.FieldParentID]
  7341  	return ok
  7342  }
  7343  
  7344  // ResetParentID resets all changes to the "parent_id" field.
  7345  func (m *TopicMutation) ResetParentID() {
  7346  	m.parent = nil
  7347  	delete(m.clearedFields, topic.FieldParentID)
  7348  }
  7349  
  7350  // AddPostIDs adds the "posts" edge to the Post entity by ids.
  7351  func (m *TopicMutation) AddPostIDs(ids ...int) {
  7352  	if m.posts == nil {
  7353  		m.posts = make(map[int]struct{})
  7354  	}
  7355  	for i := range ids {
  7356  		m.posts[ids[i]] = struct{}{}
  7357  	}
  7358  }
  7359  
  7360  // ClearPosts clears the "posts" edge to the Post entity.
  7361  func (m *TopicMutation) ClearPosts() {
  7362  	m.clearedposts = true
  7363  }
  7364  
  7365  // PostsCleared reports if the "posts" edge to the Post entity was cleared.
  7366  func (m *TopicMutation) PostsCleared() bool {
  7367  	return m.clearedposts
  7368  }
  7369  
  7370  // RemovePostIDs removes the "posts" edge to the Post entity by IDs.
  7371  func (m *TopicMutation) RemovePostIDs(ids ...int) {
  7372  	if m.removedposts == nil {
  7373  		m.removedposts = make(map[int]struct{})
  7374  	}
  7375  	for i := range ids {
  7376  		delete(m.posts, ids[i])
  7377  		m.removedposts[ids[i]] = struct{}{}
  7378  	}
  7379  }
  7380  
  7381  // RemovedPosts returns the removed IDs of the "posts" edge to the Post entity.
  7382  func (m *TopicMutation) RemovedPostsIDs() (ids []int) {
  7383  	for id := range m.removedposts {
  7384  		ids = append(ids, id)
  7385  	}
  7386  	return
  7387  }
  7388  
  7389  // PostsIDs returns the "posts" edge IDs in the mutation.
  7390  func (m *TopicMutation) PostsIDs() (ids []int) {
  7391  	for id := range m.posts {
  7392  		ids = append(ids, id)
  7393  	}
  7394  	return
  7395  }
  7396  
  7397  // ResetPosts resets all changes to the "posts" edge.
  7398  func (m *TopicMutation) ResetPosts() {
  7399  	m.posts = nil
  7400  	m.clearedposts = false
  7401  	m.removedposts = nil
  7402  }
  7403  
  7404  // AddChildIDs adds the "children" edge to the Topic entity by ids.
  7405  func (m *TopicMutation) AddChildIDs(ids ...int) {
  7406  	if m.children == nil {
  7407  		m.children = make(map[int]struct{})
  7408  	}
  7409  	for i := range ids {
  7410  		m.children[ids[i]] = struct{}{}
  7411  	}
  7412  }
  7413  
  7414  // ClearChildren clears the "children" edge to the Topic entity.
  7415  func (m *TopicMutation) ClearChildren() {
  7416  	m.clearedchildren = true
  7417  }
  7418  
  7419  // ChildrenCleared reports if the "children" edge to the Topic entity was cleared.
  7420  func (m *TopicMutation) ChildrenCleared() bool {
  7421  	return m.clearedchildren
  7422  }
  7423  
  7424  // RemoveChildIDs removes the "children" edge to the Topic entity by IDs.
  7425  func (m *TopicMutation) RemoveChildIDs(ids ...int) {
  7426  	if m.removedchildren == nil {
  7427  		m.removedchildren = make(map[int]struct{})
  7428  	}
  7429  	for i := range ids {
  7430  		delete(m.children, ids[i])
  7431  		m.removedchildren[ids[i]] = struct{}{}
  7432  	}
  7433  }
  7434  
  7435  // RemovedChildren returns the removed IDs of the "children" edge to the Topic entity.
  7436  func (m *TopicMutation) RemovedChildrenIDs() (ids []int) {
  7437  	for id := range m.removedchildren {
  7438  		ids = append(ids, id)
  7439  	}
  7440  	return
  7441  }
  7442  
  7443  // ChildrenIDs returns the "children" edge IDs in the mutation.
  7444  func (m *TopicMutation) ChildrenIDs() (ids []int) {
  7445  	for id := range m.children {
  7446  		ids = append(ids, id)
  7447  	}
  7448  	return
  7449  }
  7450  
  7451  // ResetChildren resets all changes to the "children" edge.
  7452  func (m *TopicMutation) ResetChildren() {
  7453  	m.children = nil
  7454  	m.clearedchildren = false
  7455  	m.removedchildren = nil
  7456  }
  7457  
  7458  // ClearParent clears the "parent" edge to the Topic entity.
  7459  func (m *TopicMutation) ClearParent() {
  7460  	m.clearedparent = true
  7461  }
  7462  
  7463  // ParentCleared reports if the "parent" edge to the Topic entity was cleared.
  7464  func (m *TopicMutation) ParentCleared() bool {
  7465  	return m.ParentIDCleared() || m.clearedparent
  7466  }
  7467  
  7468  // ParentIDs returns the "parent" edge IDs in the mutation.
  7469  // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  7470  // ParentID instead. It exists only for internal usage by the builders.
  7471  func (m *TopicMutation) ParentIDs() (ids []int) {
  7472  	if id := m.parent; id != nil {
  7473  		ids = append(ids, *id)
  7474  	}
  7475  	return
  7476  }
  7477  
  7478  // ResetParent resets all changes to the "parent" edge.
  7479  func (m *TopicMutation) ResetParent() {
  7480  	m.parent = nil
  7481  	m.clearedparent = false
  7482  }
  7483  
  7484  // Where appends a list predicates to the TopicMutation builder.
  7485  func (m *TopicMutation) Where(ps ...predicate.Topic) {
  7486  	m.predicates = append(m.predicates, ps...)
  7487  }
  7488  
  7489  // Op returns the operation name.
  7490  func (m *TopicMutation) Op() Op {
  7491  	return m.op
  7492  }
  7493  
  7494  // Type returns the node type of this mutation (Topic).
  7495  func (m *TopicMutation) Type() string {
  7496  	return m.typ
  7497  }
  7498  
  7499  // Fields returns all fields that were changed during this mutation. Note that in
  7500  // order to get all numeric fields that were incremented/decremented, call
  7501  // AddedFields().
  7502  func (m *TopicMutation) Fields() []string {
  7503  	fields := make([]string, 0, 9)
  7504  	if m.created_at != nil {
  7505  		fields = append(fields, topic.FieldCreatedAt)
  7506  	}
  7507  	if m.updated_at != nil {
  7508  		fields = append(fields, topic.FieldUpdatedAt)
  7509  	}
  7510  	if m.deleted_at != nil {
  7511  		fields = append(fields, topic.FieldDeletedAt)
  7512  	}
  7513  	if m.name != nil {
  7514  		fields = append(fields, topic.FieldName)
  7515  	}
  7516  	if m.slug != nil {
  7517  		fields = append(fields, topic.FieldSlug)
  7518  	}
  7519  	if m.description != nil {
  7520  		fields = append(fields, topic.FieldDescription)
  7521  	}
  7522  	if m.content != nil {
  7523  		fields = append(fields, topic.FieldContent)
  7524  	}
  7525  	if m.content_html != nil {
  7526  		fields = append(fields, topic.FieldContentHTML)
  7527  	}
  7528  	if m.parent != nil {
  7529  		fields = append(fields, topic.FieldParentID)
  7530  	}
  7531  	return fields
  7532  }
  7533  
  7534  // Field returns the value of a field with the given name. The second boolean
  7535  // return value indicates that this field was not set, or was not defined in the
  7536  // schema.
  7537  func (m *TopicMutation) Field(name string) (ent.Value, bool) {
  7538  	switch name {
  7539  	case topic.FieldCreatedAt:
  7540  		return m.CreatedAt()
  7541  	case topic.FieldUpdatedAt:
  7542  		return m.UpdatedAt()
  7543  	case topic.FieldDeletedAt:
  7544  		return m.DeletedAt()
  7545  	case topic.FieldName:
  7546  		return m.Name()
  7547  	case topic.FieldSlug:
  7548  		return m.Slug()
  7549  	case topic.FieldDescription:
  7550  		return m.Description()
  7551  	case topic.FieldContent:
  7552  		return m.Content()
  7553  	case topic.FieldContentHTML:
  7554  		return m.ContentHTML()
  7555  	case topic.FieldParentID:
  7556  		return m.ParentID()
  7557  	}
  7558  	return nil, false
  7559  }
  7560  
  7561  // OldField returns the old value of the field from the database. An error is
  7562  // returned if the mutation operation is not UpdateOne, or the query to the
  7563  // database failed.
  7564  func (m *TopicMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  7565  	switch name {
  7566  	case topic.FieldCreatedAt:
  7567  		return m.OldCreatedAt(ctx)
  7568  	case topic.FieldUpdatedAt:
  7569  		return m.OldUpdatedAt(ctx)
  7570  	case topic.FieldDeletedAt:
  7571  		return m.OldDeletedAt(ctx)
  7572  	case topic.FieldName:
  7573  		return m.OldName(ctx)
  7574  	case topic.FieldSlug:
  7575  		return m.OldSlug(ctx)
  7576  	case topic.FieldDescription:
  7577  		return m.OldDescription(ctx)
  7578  	case topic.FieldContent:
  7579  		return m.OldContent(ctx)
  7580  	case topic.FieldContentHTML:
  7581  		return m.OldContentHTML(ctx)
  7582  	case topic.FieldParentID:
  7583  		return m.OldParentID(ctx)
  7584  	}
  7585  	return nil, fmt.Errorf("unknown Topic field %s", name)
  7586  }
  7587  
  7588  // SetField sets the value of a field with the given name. It returns an error if
  7589  // the field is not defined in the schema, or if the type mismatched the field
  7590  // type.
  7591  func (m *TopicMutation) SetField(name string, value ent.Value) error {
  7592  	switch name {
  7593  	case topic.FieldCreatedAt:
  7594  		v, ok := value.(time.Time)
  7595  		if !ok {
  7596  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  7597  		}
  7598  		m.SetCreatedAt(v)
  7599  		return nil
  7600  	case topic.FieldUpdatedAt:
  7601  		v, ok := value.(time.Time)
  7602  		if !ok {
  7603  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  7604  		}
  7605  		m.SetUpdatedAt(v)
  7606  		return nil
  7607  	case topic.FieldDeletedAt:
  7608  		v, ok := value.(time.Time)
  7609  		if !ok {
  7610  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  7611  		}
  7612  		m.SetDeletedAt(v)
  7613  		return nil
  7614  	case topic.FieldName:
  7615  		v, ok := value.(string)
  7616  		if !ok {
  7617  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  7618  		}
  7619  		m.SetName(v)
  7620  		return nil
  7621  	case topic.FieldSlug:
  7622  		v, ok := value.(string)
  7623  		if !ok {
  7624  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  7625  		}
  7626  		m.SetSlug(v)
  7627  		return nil
  7628  	case topic.FieldDescription:
  7629  		v, ok := value.(string)
  7630  		if !ok {
  7631  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  7632  		}
  7633  		m.SetDescription(v)
  7634  		return nil
  7635  	case topic.FieldContent:
  7636  		v, ok := value.(string)
  7637  		if !ok {
  7638  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  7639  		}
  7640  		m.SetContent(v)
  7641  		return nil
  7642  	case topic.FieldContentHTML:
  7643  		v, ok := value.(string)
  7644  		if !ok {
  7645  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  7646  		}
  7647  		m.SetContentHTML(v)
  7648  		return nil
  7649  	case topic.FieldParentID:
  7650  		v, ok := value.(int)
  7651  		if !ok {
  7652  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  7653  		}
  7654  		m.SetParentID(v)
  7655  		return nil
  7656  	}
  7657  	return fmt.Errorf("unknown Topic field %s", name)
  7658  }
  7659  
  7660  // AddedFields returns all numeric fields that were incremented/decremented during
  7661  // this mutation.
  7662  func (m *TopicMutation) AddedFields() []string {
  7663  	var fields []string
  7664  	return fields
  7665  }
  7666  
  7667  // AddedField returns the numeric value that was incremented/decremented on a field
  7668  // with the given name. The second boolean return value indicates that this field
  7669  // was not set, or was not defined in the schema.
  7670  func (m *TopicMutation) AddedField(name string) (ent.Value, bool) {
  7671  	switch name {
  7672  	}
  7673  	return nil, false
  7674  }
  7675  
  7676  // AddField adds the value to the field with the given name. It returns an error if
  7677  // the field is not defined in the schema, or if the type mismatched the field
  7678  // type.
  7679  func (m *TopicMutation) AddField(name string, value ent.Value) error {
  7680  	switch name {
  7681  	}
  7682  	return fmt.Errorf("unknown Topic numeric field %s", name)
  7683  }
  7684  
  7685  // ClearedFields returns all nullable fields that were cleared during this
  7686  // mutation.
  7687  func (m *TopicMutation) ClearedFields() []string {
  7688  	var fields []string
  7689  	if m.FieldCleared(topic.FieldDeletedAt) {
  7690  		fields = append(fields, topic.FieldDeletedAt)
  7691  	}
  7692  	if m.FieldCleared(topic.FieldDescription) {
  7693  		fields = append(fields, topic.FieldDescription)
  7694  	}
  7695  	if m.FieldCleared(topic.FieldParentID) {
  7696  		fields = append(fields, topic.FieldParentID)
  7697  	}
  7698  	return fields
  7699  }
  7700  
  7701  // FieldCleared returns a boolean indicating if a field with the given name was
  7702  // cleared in this mutation.
  7703  func (m *TopicMutation) FieldCleared(name string) bool {
  7704  	_, ok := m.clearedFields[name]
  7705  	return ok
  7706  }
  7707  
  7708  // ClearField clears the value of the field with the given name. It returns an
  7709  // error if the field is not defined in the schema.
  7710  func (m *TopicMutation) ClearField(name string) error {
  7711  	switch name {
  7712  	case topic.FieldDeletedAt:
  7713  		m.ClearDeletedAt()
  7714  		return nil
  7715  	case topic.FieldDescription:
  7716  		m.ClearDescription()
  7717  		return nil
  7718  	case topic.FieldParentID:
  7719  		m.ClearParentID()
  7720  		return nil
  7721  	}
  7722  	return fmt.Errorf("unknown Topic nullable field %s", name)
  7723  }
  7724  
  7725  // ResetField resets all changes in the mutation for the field with the given name.
  7726  // It returns an error if the field is not defined in the schema.
  7727  func (m *TopicMutation) ResetField(name string) error {
  7728  	switch name {
  7729  	case topic.FieldCreatedAt:
  7730  		m.ResetCreatedAt()
  7731  		return nil
  7732  	case topic.FieldUpdatedAt:
  7733  		m.ResetUpdatedAt()
  7734  		return nil
  7735  	case topic.FieldDeletedAt:
  7736  		m.ResetDeletedAt()
  7737  		return nil
  7738  	case topic.FieldName:
  7739  		m.ResetName()
  7740  		return nil
  7741  	case topic.FieldSlug:
  7742  		m.ResetSlug()
  7743  		return nil
  7744  	case topic.FieldDescription:
  7745  		m.ResetDescription()
  7746  		return nil
  7747  	case topic.FieldContent:
  7748  		m.ResetContent()
  7749  		return nil
  7750  	case topic.FieldContentHTML:
  7751  		m.ResetContentHTML()
  7752  		return nil
  7753  	case topic.FieldParentID:
  7754  		m.ResetParentID()
  7755  		return nil
  7756  	}
  7757  	return fmt.Errorf("unknown Topic field %s", name)
  7758  }
  7759  
  7760  // AddedEdges returns all edge names that were set/added in this mutation.
  7761  func (m *TopicMutation) AddedEdges() []string {
  7762  	edges := make([]string, 0, 3)
  7763  	if m.posts != nil {
  7764  		edges = append(edges, topic.EdgePosts)
  7765  	}
  7766  	if m.children != nil {
  7767  		edges = append(edges, topic.EdgeChildren)
  7768  	}
  7769  	if m.parent != nil {
  7770  		edges = append(edges, topic.EdgeParent)
  7771  	}
  7772  	return edges
  7773  }
  7774  
  7775  // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  7776  // name in this mutation.
  7777  func (m *TopicMutation) AddedIDs(name string) []ent.Value {
  7778  	switch name {
  7779  	case topic.EdgePosts:
  7780  		ids := make([]ent.Value, 0, len(m.posts))
  7781  		for id := range m.posts {
  7782  			ids = append(ids, id)
  7783  		}
  7784  		return ids
  7785  	case topic.EdgeChildren:
  7786  		ids := make([]ent.Value, 0, len(m.children))
  7787  		for id := range m.children {
  7788  			ids = append(ids, id)
  7789  		}
  7790  		return ids
  7791  	case topic.EdgeParent:
  7792  		if id := m.parent; id != nil {
  7793  			return []ent.Value{*id}
  7794  		}
  7795  	}
  7796  	return nil
  7797  }
  7798  
  7799  // RemovedEdges returns all edge names that were removed in this mutation.
  7800  func (m *TopicMutation) RemovedEdges() []string {
  7801  	edges := make([]string, 0, 3)
  7802  	if m.removedposts != nil {
  7803  		edges = append(edges, topic.EdgePosts)
  7804  	}
  7805  	if m.removedchildren != nil {
  7806  		edges = append(edges, topic.EdgeChildren)
  7807  	}
  7808  	return edges
  7809  }
  7810  
  7811  // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  7812  // the given name in this mutation.
  7813  func (m *TopicMutation) RemovedIDs(name string) []ent.Value {
  7814  	switch name {
  7815  	case topic.EdgePosts:
  7816  		ids := make([]ent.Value, 0, len(m.removedposts))
  7817  		for id := range m.removedposts {
  7818  			ids = append(ids, id)
  7819  		}
  7820  		return ids
  7821  	case topic.EdgeChildren:
  7822  		ids := make([]ent.Value, 0, len(m.removedchildren))
  7823  		for id := range m.removedchildren {
  7824  			ids = append(ids, id)
  7825  		}
  7826  		return ids
  7827  	}
  7828  	return nil
  7829  }
  7830  
  7831  // ClearedEdges returns all edge names that were cleared in this mutation.
  7832  func (m *TopicMutation) ClearedEdges() []string {
  7833  	edges := make([]string, 0, 3)
  7834  	if m.clearedposts {
  7835  		edges = append(edges, topic.EdgePosts)
  7836  	}
  7837  	if m.clearedchildren {
  7838  		edges = append(edges, topic.EdgeChildren)
  7839  	}
  7840  	if m.clearedparent {
  7841  		edges = append(edges, topic.EdgeParent)
  7842  	}
  7843  	return edges
  7844  }
  7845  
  7846  // EdgeCleared returns a boolean which indicates if the edge with the given name
  7847  // was cleared in this mutation.
  7848  func (m *TopicMutation) EdgeCleared(name string) bool {
  7849  	switch name {
  7850  	case topic.EdgePosts:
  7851  		return m.clearedposts
  7852  	case topic.EdgeChildren:
  7853  		return m.clearedchildren
  7854  	case topic.EdgeParent:
  7855  		return m.clearedparent
  7856  	}
  7857  	return false
  7858  }
  7859  
  7860  // ClearEdge clears the value of the edge with the given name. It returns an error
  7861  // if that edge is not defined in the schema.
  7862  func (m *TopicMutation) ClearEdge(name string) error {
  7863  	switch name {
  7864  	case topic.EdgeParent:
  7865  		m.ClearParent()
  7866  		return nil
  7867  	}
  7868  	return fmt.Errorf("unknown Topic unique edge %s", name)
  7869  }
  7870  
  7871  // ResetEdge resets all changes to the edge with the given name in this mutation.
  7872  // It returns an error if the edge is not defined in the schema.
  7873  func (m *TopicMutation) ResetEdge(name string) error {
  7874  	switch name {
  7875  	case topic.EdgePosts:
  7876  		m.ResetPosts()
  7877  		return nil
  7878  	case topic.EdgeChildren:
  7879  		m.ResetChildren()
  7880  		return nil
  7881  	case topic.EdgeParent:
  7882  		m.ResetParent()
  7883  		return nil
  7884  	}
  7885  	return fmt.Errorf("unknown Topic edge %s", name)
  7886  }
  7887  
  7888  // UserMutation represents an operation that mutates the User nodes in the graph.
  7889  type UserMutation struct {
  7890  	config
  7891  	op                  Op
  7892  	typ                 string
  7893  	id                  *int
  7894  	created_at          *time.Time
  7895  	updated_at          *time.Time
  7896  	deleted_at          *time.Time
  7897  	username            *string
  7898  	display_name        *string
  7899  	url                 *string
  7900  	provider            *string
  7901  	provider_id         *string
  7902  	provider_username   *string
  7903  	provider_avatar     *string
  7904  	email               *string
  7905  	password            *string
  7906  	bio                 *string
  7907  	bio_html            *string
  7908  	active              *bool
  7909  	clearedFields       map[string]struct{}
  7910  	posts               map[int]struct{}
  7911  	removedposts        map[int]struct{}
  7912  	clearedposts        bool
  7913  	files               map[int]struct{}
  7914  	removedfiles        map[int]struct{}
  7915  	clearedfiles        bool
  7916  	comments            map[int]struct{}
  7917  	removedcomments     map[int]struct{}
  7918  	clearedcomments     bool
  7919  	roles               map[int]struct{}
  7920  	removedroles        map[int]struct{}
  7921  	clearedroles        bool
  7922  	avatar_image        *int
  7923  	clearedavatar_image bool
  7924  	done                bool
  7925  	oldValue            func(context.Context) (*User, error)
  7926  	predicates          []predicate.User
  7927  }
  7928  
  7929  var _ ent.Mutation = (*UserMutation)(nil)
  7930  
  7931  // userOption allows management of the mutation configuration using functional options.
  7932  type userOption func(*UserMutation)
  7933  
  7934  // newUserMutation creates new mutation for the User entity.
  7935  func newUserMutation(c config, op Op, opts ...userOption) *UserMutation {
  7936  	m := &UserMutation{
  7937  		config:        c,
  7938  		op:            op,
  7939  		typ:           TypeUser,
  7940  		clearedFields: make(map[string]struct{}),
  7941  	}
  7942  	for _, opt := range opts {
  7943  		opt(m)
  7944  	}
  7945  	return m
  7946  }
  7947  
  7948  // withUserID sets the ID field of the mutation.
  7949  func withUserID(id int) userOption {
  7950  	return func(m *UserMutation) {
  7951  		var (
  7952  			err   error
  7953  			once  sync.Once
  7954  			value *User
  7955  		)
  7956  		m.oldValue = func(ctx context.Context) (*User, error) {
  7957  			once.Do(func() {
  7958  				if m.done {
  7959  					err = errors.New("querying old values post mutation is not allowed")
  7960  				} else {
  7961  					value, err = m.Client().User.Get(ctx, id)
  7962  				}
  7963  			})
  7964  			return value, err
  7965  		}
  7966  		m.id = &id
  7967  	}
  7968  }
  7969  
  7970  // withUser sets the old User of the mutation.
  7971  func withUser(node *User) userOption {
  7972  	return func(m *UserMutation) {
  7973  		m.oldValue = func(context.Context) (*User, error) {
  7974  			return node, nil
  7975  		}
  7976  		m.id = &node.ID
  7977  	}
  7978  }
  7979  
  7980  // Client returns a new `ent.Client` from the mutation. If the mutation was
  7981  // executed in a transaction (ent.Tx), a transactional client is returned.
  7982  func (m UserMutation) Client() *Client {
  7983  	client := &Client{config: m.config}
  7984  	client.init()
  7985  	return client
  7986  }
  7987  
  7988  // Tx returns an `ent.Tx` for mutations that were executed in transactions;
  7989  // it returns an error otherwise.
  7990  func (m UserMutation) Tx() (*Tx, error) {
  7991  	if _, ok := m.driver.(*txDriver); !ok {
  7992  		return nil, errors.New("ent: mutation is not running in a transaction")
  7993  	}
  7994  	tx := &Tx{config: m.config}
  7995  	tx.init()
  7996  	return tx, nil
  7997  }
  7998  
  7999  // ID returns the ID value in the mutation. Note that the ID is only available
  8000  // if it was provided to the builder or after it was returned from the database.
  8001  func (m *UserMutation) ID() (id int, exists bool) {
  8002  	if m.id == nil {
  8003  		return
  8004  	}
  8005  	return *m.id, true
  8006  }
  8007  
  8008  // IDs queries the database and returns the entity ids that match the mutation's predicate.
  8009  // That means, if the mutation is applied within a transaction with an isolation level such
  8010  // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
  8011  // or updated by the mutation.
  8012  func (m *UserMutation) IDs(ctx context.Context) ([]int, error) {
  8013  	switch {
  8014  	case m.op.Is(OpUpdateOne | OpDeleteOne):
  8015  		id, exists := m.ID()
  8016  		if exists {
  8017  			return []int{id}, nil
  8018  		}
  8019  		fallthrough
  8020  	case m.op.Is(OpUpdate | OpDelete):
  8021  		return m.Client().User.Query().Where(m.predicates...).IDs(ctx)
  8022  	default:
  8023  		return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
  8024  	}
  8025  }
  8026  
  8027  // SetCreatedAt sets the "created_at" field.
  8028  func (m *UserMutation) SetCreatedAt(t time.Time) {
  8029  	m.created_at = &t
  8030  }
  8031  
  8032  // CreatedAt returns the value of the "created_at" field in the mutation.
  8033  func (m *UserMutation) CreatedAt() (r time.Time, exists bool) {
  8034  	v := m.created_at
  8035  	if v == nil {
  8036  		return
  8037  	}
  8038  	return *v, true
  8039  }
  8040  
  8041  // OldCreatedAt returns the old "created_at" field's value of the User entity.
  8042  // If the User object wasn't provided to the builder, the object is fetched from the database.
  8043  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  8044  func (m *UserMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
  8045  	if !m.op.Is(OpUpdateOne) {
  8046  		return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
  8047  	}
  8048  	if m.id == nil || m.oldValue == nil {
  8049  		return v, errors.New("OldCreatedAt requires an ID field in the mutation")
  8050  	}
  8051  	oldValue, err := m.oldValue(ctx)
  8052  	if err != nil {
  8053  		return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
  8054  	}
  8055  	return oldValue.CreatedAt, nil
  8056  }
  8057  
  8058  // ResetCreatedAt resets all changes to the "created_at" field.
  8059  func (m *UserMutation) ResetCreatedAt() {
  8060  	m.created_at = nil
  8061  }
  8062  
  8063  // SetUpdatedAt sets the "updated_at" field.
  8064  func (m *UserMutation) SetUpdatedAt(t time.Time) {
  8065  	m.updated_at = &t
  8066  }
  8067  
  8068  // UpdatedAt returns the value of the "updated_at" field in the mutation.
  8069  func (m *UserMutation) UpdatedAt() (r time.Time, exists bool) {
  8070  	v := m.updated_at
  8071  	if v == nil {
  8072  		return
  8073  	}
  8074  	return *v, true
  8075  }
  8076  
  8077  // OldUpdatedAt returns the old "updated_at" field's value of the User entity.
  8078  // If the User object wasn't provided to the builder, the object is fetched from the database.
  8079  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  8080  func (m *UserMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
  8081  	if !m.op.Is(OpUpdateOne) {
  8082  		return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
  8083  	}
  8084  	if m.id == nil || m.oldValue == nil {
  8085  		return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
  8086  	}
  8087  	oldValue, err := m.oldValue(ctx)
  8088  	if err != nil {
  8089  		return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
  8090  	}
  8091  	return oldValue.UpdatedAt, nil
  8092  }
  8093  
  8094  // ResetUpdatedAt resets all changes to the "updated_at" field.
  8095  func (m *UserMutation) ResetUpdatedAt() {
  8096  	m.updated_at = nil
  8097  }
  8098  
  8099  // SetDeletedAt sets the "deleted_at" field.
  8100  func (m *UserMutation) SetDeletedAt(t time.Time) {
  8101  	m.deleted_at = &t
  8102  }
  8103  
  8104  // DeletedAt returns the value of the "deleted_at" field in the mutation.
  8105  func (m *UserMutation) DeletedAt() (r time.Time, exists bool) {
  8106  	v := m.deleted_at
  8107  	if v == nil {
  8108  		return
  8109  	}
  8110  	return *v, true
  8111  }
  8112  
  8113  // OldDeletedAt returns the old "deleted_at" field's value of the User entity.
  8114  // If the User object wasn't provided to the builder, the object is fetched from the database.
  8115  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  8116  func (m *UserMutation) OldDeletedAt(ctx context.Context) (v time.Time, err error) {
  8117  	if !m.op.Is(OpUpdateOne) {
  8118  		return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
  8119  	}
  8120  	if m.id == nil || m.oldValue == nil {
  8121  		return v, errors.New("OldDeletedAt requires an ID field in the mutation")
  8122  	}
  8123  	oldValue, err := m.oldValue(ctx)
  8124  	if err != nil {
  8125  		return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
  8126  	}
  8127  	return oldValue.DeletedAt, nil
  8128  }
  8129  
  8130  // ClearDeletedAt clears the value of the "deleted_at" field.
  8131  func (m *UserMutation) ClearDeletedAt() {
  8132  	m.deleted_at = nil
  8133  	m.clearedFields[user.FieldDeletedAt] = struct{}{}
  8134  }
  8135  
  8136  // DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
  8137  func (m *UserMutation) DeletedAtCleared() bool {
  8138  	_, ok := m.clearedFields[user.FieldDeletedAt]
  8139  	return ok
  8140  }
  8141  
  8142  // ResetDeletedAt resets all changes to the "deleted_at" field.
  8143  func (m *UserMutation) ResetDeletedAt() {
  8144  	m.deleted_at = nil
  8145  	delete(m.clearedFields, user.FieldDeletedAt)
  8146  }
  8147  
  8148  // SetUsername sets the "username" field.
  8149  func (m *UserMutation) SetUsername(s string) {
  8150  	m.username = &s
  8151  }
  8152  
  8153  // Username returns the value of the "username" field in the mutation.
  8154  func (m *UserMutation) Username() (r string, exists bool) {
  8155  	v := m.username
  8156  	if v == nil {
  8157  		return
  8158  	}
  8159  	return *v, true
  8160  }
  8161  
  8162  // OldUsername returns the old "username" field's value of the User entity.
  8163  // If the User object wasn't provided to the builder, the object is fetched from the database.
  8164  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  8165  func (m *UserMutation) OldUsername(ctx context.Context) (v string, err error) {
  8166  	if !m.op.Is(OpUpdateOne) {
  8167  		return v, errors.New("OldUsername is only allowed on UpdateOne operations")
  8168  	}
  8169  	if m.id == nil || m.oldValue == nil {
  8170  		return v, errors.New("OldUsername requires an ID field in the mutation")
  8171  	}
  8172  	oldValue, err := m.oldValue(ctx)
  8173  	if err != nil {
  8174  		return v, fmt.Errorf("querying old value for OldUsername: %w", err)
  8175  	}
  8176  	return oldValue.Username, nil
  8177  }
  8178  
  8179  // ResetUsername resets all changes to the "username" field.
  8180  func (m *UserMutation) ResetUsername() {
  8181  	m.username = nil
  8182  }
  8183  
  8184  // SetDisplayName sets the "display_name" field.
  8185  func (m *UserMutation) SetDisplayName(s string) {
  8186  	m.display_name = &s
  8187  }
  8188  
  8189  // DisplayName returns the value of the "display_name" field in the mutation.
  8190  func (m *UserMutation) DisplayName() (r string, exists bool) {
  8191  	v := m.display_name
  8192  	if v == nil {
  8193  		return
  8194  	}
  8195  	return *v, true
  8196  }
  8197  
  8198  // OldDisplayName returns the old "display_name" field's value of the User entity.
  8199  // If the User object wasn't provided to the builder, the object is fetched from the database.
  8200  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  8201  func (m *UserMutation) OldDisplayName(ctx context.Context) (v string, err error) {
  8202  	if !m.op.Is(OpUpdateOne) {
  8203  		return v, errors.New("OldDisplayName is only allowed on UpdateOne operations")
  8204  	}
  8205  	if m.id == nil || m.oldValue == nil {
  8206  		return v, errors.New("OldDisplayName requires an ID field in the mutation")
  8207  	}
  8208  	oldValue, err := m.oldValue(ctx)
  8209  	if err != nil {
  8210  		return v, fmt.Errorf("querying old value for OldDisplayName: %w", err)
  8211  	}
  8212  	return oldValue.DisplayName, nil
  8213  }
  8214  
  8215  // ClearDisplayName clears the value of the "display_name" field.
  8216  func (m *UserMutation) ClearDisplayName() {
  8217  	m.display_name = nil
  8218  	m.clearedFields[user.FieldDisplayName] = struct{}{}
  8219  }
  8220  
  8221  // DisplayNameCleared returns if the "display_name" field was cleared in this mutation.
  8222  func (m *UserMutation) DisplayNameCleared() bool {
  8223  	_, ok := m.clearedFields[user.FieldDisplayName]
  8224  	return ok
  8225  }
  8226  
  8227  // ResetDisplayName resets all changes to the "display_name" field.
  8228  func (m *UserMutation) ResetDisplayName() {
  8229  	m.display_name = nil
  8230  	delete(m.clearedFields, user.FieldDisplayName)
  8231  }
  8232  
  8233  // SetURL sets the "url" field.
  8234  func (m *UserMutation) SetURL(s string) {
  8235  	m.url = &s
  8236  }
  8237  
  8238  // URL returns the value of the "url" field in the mutation.
  8239  func (m *UserMutation) URL() (r string, exists bool) {
  8240  	v := m.url
  8241  	if v == nil {
  8242  		return
  8243  	}
  8244  	return *v, true
  8245  }
  8246  
  8247  // OldURL returns the old "url" field's value of the User entity.
  8248  // If the User object wasn't provided to the builder, the object is fetched from the database.
  8249  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  8250  func (m *UserMutation) OldURL(ctx context.Context) (v string, err error) {
  8251  	if !m.op.Is(OpUpdateOne) {
  8252  		return v, errors.New("OldURL is only allowed on UpdateOne operations")
  8253  	}
  8254  	if m.id == nil || m.oldValue == nil {
  8255  		return v, errors.New("OldURL requires an ID field in the mutation")
  8256  	}
  8257  	oldValue, err := m.oldValue(ctx)
  8258  	if err != nil {
  8259  		return v, fmt.Errorf("querying old value for OldURL: %w", err)
  8260  	}
  8261  	return oldValue.URL, nil
  8262  }
  8263  
  8264  // ClearURL clears the value of the "url" field.
  8265  func (m *UserMutation) ClearURL() {
  8266  	m.url = nil
  8267  	m.clearedFields[user.FieldURL] = struct{}{}
  8268  }
  8269  
  8270  // URLCleared returns if the "url" field was cleared in this mutation.
  8271  func (m *UserMutation) URLCleared() bool {
  8272  	_, ok := m.clearedFields[user.FieldURL]
  8273  	return ok
  8274  }
  8275  
  8276  // ResetURL resets all changes to the "url" field.
  8277  func (m *UserMutation) ResetURL() {
  8278  	m.url = nil
  8279  	delete(m.clearedFields, user.FieldURL)
  8280  }
  8281  
  8282  // SetProvider sets the "provider" field.
  8283  func (m *UserMutation) SetProvider(s string) {
  8284  	m.provider = &s
  8285  }
  8286  
  8287  // Provider returns the value of the "provider" field in the mutation.
  8288  func (m *UserMutation) Provider() (r string, exists bool) {
  8289  	v := m.provider
  8290  	if v == nil {
  8291  		return
  8292  	}
  8293  	return *v, true
  8294  }
  8295  
  8296  // OldProvider returns the old "provider" field's value of the User entity.
  8297  // If the User object wasn't provided to the builder, the object is fetched from the database.
  8298  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  8299  func (m *UserMutation) OldProvider(ctx context.Context) (v string, err error) {
  8300  	if !m.op.Is(OpUpdateOne) {
  8301  		return v, errors.New("OldProvider is only allowed on UpdateOne operations")
  8302  	}
  8303  	if m.id == nil || m.oldValue == nil {
  8304  		return v, errors.New("OldProvider requires an ID field in the mutation")
  8305  	}
  8306  	oldValue, err := m.oldValue(ctx)
  8307  	if err != nil {
  8308  		return v, fmt.Errorf("querying old value for OldProvider: %w", err)
  8309  	}
  8310  	return oldValue.Provider, nil
  8311  }
  8312  
  8313  // ClearProvider clears the value of the "provider" field.
  8314  func (m *UserMutation) ClearProvider() {
  8315  	m.provider = nil
  8316  	m.clearedFields[user.FieldProvider] = struct{}{}
  8317  }
  8318  
  8319  // ProviderCleared returns if the "provider" field was cleared in this mutation.
  8320  func (m *UserMutation) ProviderCleared() bool {
  8321  	_, ok := m.clearedFields[user.FieldProvider]
  8322  	return ok
  8323  }
  8324  
  8325  // ResetProvider resets all changes to the "provider" field.
  8326  func (m *UserMutation) ResetProvider() {
  8327  	m.provider = nil
  8328  	delete(m.clearedFields, user.FieldProvider)
  8329  }
  8330  
  8331  // SetProviderID sets the "provider_id" field.
  8332  func (m *UserMutation) SetProviderID(s string) {
  8333  	m.provider_id = &s
  8334  }
  8335  
  8336  // ProviderID returns the value of the "provider_id" field in the mutation.
  8337  func (m *UserMutation) ProviderID() (r string, exists bool) {
  8338  	v := m.provider_id
  8339  	if v == nil {
  8340  		return
  8341  	}
  8342  	return *v, true
  8343  }
  8344  
  8345  // OldProviderID returns the old "provider_id" field's value of the User entity.
  8346  // If the User object wasn't provided to the builder, the object is fetched from the database.
  8347  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  8348  func (m *UserMutation) OldProviderID(ctx context.Context) (v string, err error) {
  8349  	if !m.op.Is(OpUpdateOne) {
  8350  		return v, errors.New("OldProviderID is only allowed on UpdateOne operations")
  8351  	}
  8352  	if m.id == nil || m.oldValue == nil {
  8353  		return v, errors.New("OldProviderID requires an ID field in the mutation")
  8354  	}
  8355  	oldValue, err := m.oldValue(ctx)
  8356  	if err != nil {
  8357  		return v, fmt.Errorf("querying old value for OldProviderID: %w", err)
  8358  	}
  8359  	return oldValue.ProviderID, nil
  8360  }
  8361  
  8362  // ClearProviderID clears the value of the "provider_id" field.
  8363  func (m *UserMutation) ClearProviderID() {
  8364  	m.provider_id = nil
  8365  	m.clearedFields[user.FieldProviderID] = struct{}{}
  8366  }
  8367  
  8368  // ProviderIDCleared returns if the "provider_id" field was cleared in this mutation.
  8369  func (m *UserMutation) ProviderIDCleared() bool {
  8370  	_, ok := m.clearedFields[user.FieldProviderID]
  8371  	return ok
  8372  }
  8373  
  8374  // ResetProviderID resets all changes to the "provider_id" field.
  8375  func (m *UserMutation) ResetProviderID() {
  8376  	m.provider_id = nil
  8377  	delete(m.clearedFields, user.FieldProviderID)
  8378  }
  8379  
  8380  // SetProviderUsername sets the "provider_username" field.
  8381  func (m *UserMutation) SetProviderUsername(s string) {
  8382  	m.provider_username = &s
  8383  }
  8384  
  8385  // ProviderUsername returns the value of the "provider_username" field in the mutation.
  8386  func (m *UserMutation) ProviderUsername() (r string, exists bool) {
  8387  	v := m.provider_username
  8388  	if v == nil {
  8389  		return
  8390  	}
  8391  	return *v, true
  8392  }
  8393  
  8394  // OldProviderUsername returns the old "provider_username" field's value of the User entity.
  8395  // If the User object wasn't provided to the builder, the object is fetched from the database.
  8396  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  8397  func (m *UserMutation) OldProviderUsername(ctx context.Context) (v string, err error) {
  8398  	if !m.op.Is(OpUpdateOne) {
  8399  		return v, errors.New("OldProviderUsername is only allowed on UpdateOne operations")
  8400  	}
  8401  	if m.id == nil || m.oldValue == nil {
  8402  		return v, errors.New("OldProviderUsername requires an ID field in the mutation")
  8403  	}
  8404  	oldValue, err := m.oldValue(ctx)
  8405  	if err != nil {
  8406  		return v, fmt.Errorf("querying old value for OldProviderUsername: %w", err)
  8407  	}
  8408  	return oldValue.ProviderUsername, nil
  8409  }
  8410  
  8411  // ClearProviderUsername clears the value of the "provider_username" field.
  8412  func (m *UserMutation) ClearProviderUsername() {
  8413  	m.provider_username = nil
  8414  	m.clearedFields[user.FieldProviderUsername] = struct{}{}
  8415  }
  8416  
  8417  // ProviderUsernameCleared returns if the "provider_username" field was cleared in this mutation.
  8418  func (m *UserMutation) ProviderUsernameCleared() bool {
  8419  	_, ok := m.clearedFields[user.FieldProviderUsername]
  8420  	return ok
  8421  }
  8422  
  8423  // ResetProviderUsername resets all changes to the "provider_username" field.
  8424  func (m *UserMutation) ResetProviderUsername() {
  8425  	m.provider_username = nil
  8426  	delete(m.clearedFields, user.FieldProviderUsername)
  8427  }
  8428  
  8429  // SetProviderAvatar sets the "provider_avatar" field.
  8430  func (m *UserMutation) SetProviderAvatar(s string) {
  8431  	m.provider_avatar = &s
  8432  }
  8433  
  8434  // ProviderAvatar returns the value of the "provider_avatar" field in the mutation.
  8435  func (m *UserMutation) ProviderAvatar() (r string, exists bool) {
  8436  	v := m.provider_avatar
  8437  	if v == nil {
  8438  		return
  8439  	}
  8440  	return *v, true
  8441  }
  8442  
  8443  // OldProviderAvatar returns the old "provider_avatar" field's value of the User entity.
  8444  // If the User object wasn't provided to the builder, the object is fetched from the database.
  8445  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  8446  func (m *UserMutation) OldProviderAvatar(ctx context.Context) (v string, err error) {
  8447  	if !m.op.Is(OpUpdateOne) {
  8448  		return v, errors.New("OldProviderAvatar is only allowed on UpdateOne operations")
  8449  	}
  8450  	if m.id == nil || m.oldValue == nil {
  8451  		return v, errors.New("OldProviderAvatar requires an ID field in the mutation")
  8452  	}
  8453  	oldValue, err := m.oldValue(ctx)
  8454  	if err != nil {
  8455  		return v, fmt.Errorf("querying old value for OldProviderAvatar: %w", err)
  8456  	}
  8457  	return oldValue.ProviderAvatar, nil
  8458  }
  8459  
  8460  // ClearProviderAvatar clears the value of the "provider_avatar" field.
  8461  func (m *UserMutation) ClearProviderAvatar() {
  8462  	m.provider_avatar = nil
  8463  	m.clearedFields[user.FieldProviderAvatar] = struct{}{}
  8464  }
  8465  
  8466  // ProviderAvatarCleared returns if the "provider_avatar" field was cleared in this mutation.
  8467  func (m *UserMutation) ProviderAvatarCleared() bool {
  8468  	_, ok := m.clearedFields[user.FieldProviderAvatar]
  8469  	return ok
  8470  }
  8471  
  8472  // ResetProviderAvatar resets all changes to the "provider_avatar" field.
  8473  func (m *UserMutation) ResetProviderAvatar() {
  8474  	m.provider_avatar = nil
  8475  	delete(m.clearedFields, user.FieldProviderAvatar)
  8476  }
  8477  
  8478  // SetEmail sets the "email" field.
  8479  func (m *UserMutation) SetEmail(s string) {
  8480  	m.email = &s
  8481  }
  8482  
  8483  // Email returns the value of the "email" field in the mutation.
  8484  func (m *UserMutation) Email() (r string, exists bool) {
  8485  	v := m.email
  8486  	if v == nil {
  8487  		return
  8488  	}
  8489  	return *v, true
  8490  }
  8491  
  8492  // OldEmail returns the old "email" field's value of the User entity.
  8493  // If the User object wasn't provided to the builder, the object is fetched from the database.
  8494  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  8495  func (m *UserMutation) OldEmail(ctx context.Context) (v string, err error) {
  8496  	if !m.op.Is(OpUpdateOne) {
  8497  		return v, errors.New("OldEmail is only allowed on UpdateOne operations")
  8498  	}
  8499  	if m.id == nil || m.oldValue == nil {
  8500  		return v, errors.New("OldEmail requires an ID field in the mutation")
  8501  	}
  8502  	oldValue, err := m.oldValue(ctx)
  8503  	if err != nil {
  8504  		return v, fmt.Errorf("querying old value for OldEmail: %w", err)
  8505  	}
  8506  	return oldValue.Email, nil
  8507  }
  8508  
  8509  // ClearEmail clears the value of the "email" field.
  8510  func (m *UserMutation) ClearEmail() {
  8511  	m.email = nil
  8512  	m.clearedFields[user.FieldEmail] = struct{}{}
  8513  }
  8514  
  8515  // EmailCleared returns if the "email" field was cleared in this mutation.
  8516  func (m *UserMutation) EmailCleared() bool {
  8517  	_, ok := m.clearedFields[user.FieldEmail]
  8518  	return ok
  8519  }
  8520  
  8521  // ResetEmail resets all changes to the "email" field.
  8522  func (m *UserMutation) ResetEmail() {
  8523  	m.email = nil
  8524  	delete(m.clearedFields, user.FieldEmail)
  8525  }
  8526  
  8527  // SetPassword sets the "password" field.
  8528  func (m *UserMutation) SetPassword(s string) {
  8529  	m.password = &s
  8530  }
  8531  
  8532  // Password returns the value of the "password" field in the mutation.
  8533  func (m *UserMutation) Password() (r string, exists bool) {
  8534  	v := m.password
  8535  	if v == nil {
  8536  		return
  8537  	}
  8538  	return *v, true
  8539  }
  8540  
  8541  // OldPassword returns the old "password" field's value of the User entity.
  8542  // If the User object wasn't provided to the builder, the object is fetched from the database.
  8543  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  8544  func (m *UserMutation) OldPassword(ctx context.Context) (v string, err error) {
  8545  	if !m.op.Is(OpUpdateOne) {
  8546  		return v, errors.New("OldPassword is only allowed on UpdateOne operations")
  8547  	}
  8548  	if m.id == nil || m.oldValue == nil {
  8549  		return v, errors.New("OldPassword requires an ID field in the mutation")
  8550  	}
  8551  	oldValue, err := m.oldValue(ctx)
  8552  	if err != nil {
  8553  		return v, fmt.Errorf("querying old value for OldPassword: %w", err)
  8554  	}
  8555  	return oldValue.Password, nil
  8556  }
  8557  
  8558  // ClearPassword clears the value of the "password" field.
  8559  func (m *UserMutation) ClearPassword() {
  8560  	m.password = nil
  8561  	m.clearedFields[user.FieldPassword] = struct{}{}
  8562  }
  8563  
  8564  // PasswordCleared returns if the "password" field was cleared in this mutation.
  8565  func (m *UserMutation) PasswordCleared() bool {
  8566  	_, ok := m.clearedFields[user.FieldPassword]
  8567  	return ok
  8568  }
  8569  
  8570  // ResetPassword resets all changes to the "password" field.
  8571  func (m *UserMutation) ResetPassword() {
  8572  	m.password = nil
  8573  	delete(m.clearedFields, user.FieldPassword)
  8574  }
  8575  
  8576  // SetBio sets the "bio" field.
  8577  func (m *UserMutation) SetBio(s string) {
  8578  	m.bio = &s
  8579  }
  8580  
  8581  // Bio returns the value of the "bio" field in the mutation.
  8582  func (m *UserMutation) Bio() (r string, exists bool) {
  8583  	v := m.bio
  8584  	if v == nil {
  8585  		return
  8586  	}
  8587  	return *v, true
  8588  }
  8589  
  8590  // OldBio returns the old "bio" field's value of the User entity.
  8591  // If the User object wasn't provided to the builder, the object is fetched from the database.
  8592  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  8593  func (m *UserMutation) OldBio(ctx context.Context) (v string, err error) {
  8594  	if !m.op.Is(OpUpdateOne) {
  8595  		return v, errors.New("OldBio is only allowed on UpdateOne operations")
  8596  	}
  8597  	if m.id == nil || m.oldValue == nil {
  8598  		return v, errors.New("OldBio requires an ID field in the mutation")
  8599  	}
  8600  	oldValue, err := m.oldValue(ctx)
  8601  	if err != nil {
  8602  		return v, fmt.Errorf("querying old value for OldBio: %w", err)
  8603  	}
  8604  	return oldValue.Bio, nil
  8605  }
  8606  
  8607  // ClearBio clears the value of the "bio" field.
  8608  func (m *UserMutation) ClearBio() {
  8609  	m.bio = nil
  8610  	m.clearedFields[user.FieldBio] = struct{}{}
  8611  }
  8612  
  8613  // BioCleared returns if the "bio" field was cleared in this mutation.
  8614  func (m *UserMutation) BioCleared() bool {
  8615  	_, ok := m.clearedFields[user.FieldBio]
  8616  	return ok
  8617  }
  8618  
  8619  // ResetBio resets all changes to the "bio" field.
  8620  func (m *UserMutation) ResetBio() {
  8621  	m.bio = nil
  8622  	delete(m.clearedFields, user.FieldBio)
  8623  }
  8624  
  8625  // SetBioHTML sets the "bio_html" field.
  8626  func (m *UserMutation) SetBioHTML(s string) {
  8627  	m.bio_html = &s
  8628  }
  8629  
  8630  // BioHTML returns the value of the "bio_html" field in the mutation.
  8631  func (m *UserMutation) BioHTML() (r string, exists bool) {
  8632  	v := m.bio_html
  8633  	if v == nil {
  8634  		return
  8635  	}
  8636  	return *v, true
  8637  }
  8638  
  8639  // OldBioHTML returns the old "bio_html" field's value of the User entity.
  8640  // If the User object wasn't provided to the builder, the object is fetched from the database.
  8641  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  8642  func (m *UserMutation) OldBioHTML(ctx context.Context) (v string, err error) {
  8643  	if !m.op.Is(OpUpdateOne) {
  8644  		return v, errors.New("OldBioHTML is only allowed on UpdateOne operations")
  8645  	}
  8646  	if m.id == nil || m.oldValue == nil {
  8647  		return v, errors.New("OldBioHTML requires an ID field in the mutation")
  8648  	}
  8649  	oldValue, err := m.oldValue(ctx)
  8650  	if err != nil {
  8651  		return v, fmt.Errorf("querying old value for OldBioHTML: %w", err)
  8652  	}
  8653  	return oldValue.BioHTML, nil
  8654  }
  8655  
  8656  // ClearBioHTML clears the value of the "bio_html" field.
  8657  func (m *UserMutation) ClearBioHTML() {
  8658  	m.bio_html = nil
  8659  	m.clearedFields[user.FieldBioHTML] = struct{}{}
  8660  }
  8661  
  8662  // BioHTMLCleared returns if the "bio_html" field was cleared in this mutation.
  8663  func (m *UserMutation) BioHTMLCleared() bool {
  8664  	_, ok := m.clearedFields[user.FieldBioHTML]
  8665  	return ok
  8666  }
  8667  
  8668  // ResetBioHTML resets all changes to the "bio_html" field.
  8669  func (m *UserMutation) ResetBioHTML() {
  8670  	m.bio_html = nil
  8671  	delete(m.clearedFields, user.FieldBioHTML)
  8672  }
  8673  
  8674  // SetActive sets the "active" field.
  8675  func (m *UserMutation) SetActive(b bool) {
  8676  	m.active = &b
  8677  }
  8678  
  8679  // Active returns the value of the "active" field in the mutation.
  8680  func (m *UserMutation) Active() (r bool, exists bool) {
  8681  	v := m.active
  8682  	if v == nil {
  8683  		return
  8684  	}
  8685  	return *v, true
  8686  }
  8687  
  8688  // OldActive returns the old "active" field's value of the User entity.
  8689  // If the User object wasn't provided to the builder, the object is fetched from the database.
  8690  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  8691  func (m *UserMutation) OldActive(ctx context.Context) (v bool, err error) {
  8692  	if !m.op.Is(OpUpdateOne) {
  8693  		return v, errors.New("OldActive is only allowed on UpdateOne operations")
  8694  	}
  8695  	if m.id == nil || m.oldValue == nil {
  8696  		return v, errors.New("OldActive requires an ID field in the mutation")
  8697  	}
  8698  	oldValue, err := m.oldValue(ctx)
  8699  	if err != nil {
  8700  		return v, fmt.Errorf("querying old value for OldActive: %w", err)
  8701  	}
  8702  	return oldValue.Active, nil
  8703  }
  8704  
  8705  // ResetActive resets all changes to the "active" field.
  8706  func (m *UserMutation) ResetActive() {
  8707  	m.active = nil
  8708  }
  8709  
  8710  // SetAvatarImageID sets the "avatar_image_id" field.
  8711  func (m *UserMutation) SetAvatarImageID(i int) {
  8712  	m.avatar_image = &i
  8713  }
  8714  
  8715  // AvatarImageID returns the value of the "avatar_image_id" field in the mutation.
  8716  func (m *UserMutation) AvatarImageID() (r int, exists bool) {
  8717  	v := m.avatar_image
  8718  	if v == nil {
  8719  		return
  8720  	}
  8721  	return *v, true
  8722  }
  8723  
  8724  // OldAvatarImageID returns the old "avatar_image_id" field's value of the User entity.
  8725  // If the User object wasn't provided to the builder, the object is fetched from the database.
  8726  // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
  8727  func (m *UserMutation) OldAvatarImageID(ctx context.Context) (v int, err error) {
  8728  	if !m.op.Is(OpUpdateOne) {
  8729  		return v, errors.New("OldAvatarImageID is only allowed on UpdateOne operations")
  8730  	}
  8731  	if m.id == nil || m.oldValue == nil {
  8732  		return v, errors.New("OldAvatarImageID requires an ID field in the mutation")
  8733  	}
  8734  	oldValue, err := m.oldValue(ctx)
  8735  	if err != nil {
  8736  		return v, fmt.Errorf("querying old value for OldAvatarImageID: %w", err)
  8737  	}
  8738  	return oldValue.AvatarImageID, nil
  8739  }
  8740  
  8741  // ClearAvatarImageID clears the value of the "avatar_image_id" field.
  8742  func (m *UserMutation) ClearAvatarImageID() {
  8743  	m.avatar_image = nil
  8744  	m.clearedFields[user.FieldAvatarImageID] = struct{}{}
  8745  }
  8746  
  8747  // AvatarImageIDCleared returns if the "avatar_image_id" field was cleared in this mutation.
  8748  func (m *UserMutation) AvatarImageIDCleared() bool {
  8749  	_, ok := m.clearedFields[user.FieldAvatarImageID]
  8750  	return ok
  8751  }
  8752  
  8753  // ResetAvatarImageID resets all changes to the "avatar_image_id" field.
  8754  func (m *UserMutation) ResetAvatarImageID() {
  8755  	m.avatar_image = nil
  8756  	delete(m.clearedFields, user.FieldAvatarImageID)
  8757  }
  8758  
  8759  // AddPostIDs adds the "posts" edge to the Post entity by ids.
  8760  func (m *UserMutation) AddPostIDs(ids ...int) {
  8761  	if m.posts == nil {
  8762  		m.posts = make(map[int]struct{})
  8763  	}
  8764  	for i := range ids {
  8765  		m.posts[ids[i]] = struct{}{}
  8766  	}
  8767  }
  8768  
  8769  // ClearPosts clears the "posts" edge to the Post entity.
  8770  func (m *UserMutation) ClearPosts() {
  8771  	m.clearedposts = true
  8772  }
  8773  
  8774  // PostsCleared reports if the "posts" edge to the Post entity was cleared.
  8775  func (m *UserMutation) PostsCleared() bool {
  8776  	return m.clearedposts
  8777  }
  8778  
  8779  // RemovePostIDs removes the "posts" edge to the Post entity by IDs.
  8780  func (m *UserMutation) RemovePostIDs(ids ...int) {
  8781  	if m.removedposts == nil {
  8782  		m.removedposts = make(map[int]struct{})
  8783  	}
  8784  	for i := range ids {
  8785  		delete(m.posts, ids[i])
  8786  		m.removedposts[ids[i]] = struct{}{}
  8787  	}
  8788  }
  8789  
  8790  // RemovedPosts returns the removed IDs of the "posts" edge to the Post entity.
  8791  func (m *UserMutation) RemovedPostsIDs() (ids []int) {
  8792  	for id := range m.removedposts {
  8793  		ids = append(ids, id)
  8794  	}
  8795  	return
  8796  }
  8797  
  8798  // PostsIDs returns the "posts" edge IDs in the mutation.
  8799  func (m *UserMutation) PostsIDs() (ids []int) {
  8800  	for id := range m.posts {
  8801  		ids = append(ids, id)
  8802  	}
  8803  	return
  8804  }
  8805  
  8806  // ResetPosts resets all changes to the "posts" edge.
  8807  func (m *UserMutation) ResetPosts() {
  8808  	m.posts = nil
  8809  	m.clearedposts = false
  8810  	m.removedposts = nil
  8811  }
  8812  
  8813  // AddFileIDs adds the "files" edge to the File entity by ids.
  8814  func (m *UserMutation) AddFileIDs(ids ...int) {
  8815  	if m.files == nil {
  8816  		m.files = make(map[int]struct{})
  8817  	}
  8818  	for i := range ids {
  8819  		m.files[ids[i]] = struct{}{}
  8820  	}
  8821  }
  8822  
  8823  // ClearFiles clears the "files" edge to the File entity.
  8824  func (m *UserMutation) ClearFiles() {
  8825  	m.clearedfiles = true
  8826  }
  8827  
  8828  // FilesCleared reports if the "files" edge to the File entity was cleared.
  8829  func (m *UserMutation) FilesCleared() bool {
  8830  	return m.clearedfiles
  8831  }
  8832  
  8833  // RemoveFileIDs removes the "files" edge to the File entity by IDs.
  8834  func (m *UserMutation) RemoveFileIDs(ids ...int) {
  8835  	if m.removedfiles == nil {
  8836  		m.removedfiles = make(map[int]struct{})
  8837  	}
  8838  	for i := range ids {
  8839  		delete(m.files, ids[i])
  8840  		m.removedfiles[ids[i]] = struct{}{}
  8841  	}
  8842  }
  8843  
  8844  // RemovedFiles returns the removed IDs of the "files" edge to the File entity.
  8845  func (m *UserMutation) RemovedFilesIDs() (ids []int) {
  8846  	for id := range m.removedfiles {
  8847  		ids = append(ids, id)
  8848  	}
  8849  	return
  8850  }
  8851  
  8852  // FilesIDs returns the "files" edge IDs in the mutation.
  8853  func (m *UserMutation) FilesIDs() (ids []int) {
  8854  	for id := range m.files {
  8855  		ids = append(ids, id)
  8856  	}
  8857  	return
  8858  }
  8859  
  8860  // ResetFiles resets all changes to the "files" edge.
  8861  func (m *UserMutation) ResetFiles() {
  8862  	m.files = nil
  8863  	m.clearedfiles = false
  8864  	m.removedfiles = nil
  8865  }
  8866  
  8867  // AddCommentIDs adds the "comments" edge to the Comment entity by ids.
  8868  func (m *UserMutation) AddCommentIDs(ids ...int) {
  8869  	if m.comments == nil {
  8870  		m.comments = make(map[int]struct{})
  8871  	}
  8872  	for i := range ids {
  8873  		m.comments[ids[i]] = struct{}{}
  8874  	}
  8875  }
  8876  
  8877  // ClearComments clears the "comments" edge to the Comment entity.
  8878  func (m *UserMutation) ClearComments() {
  8879  	m.clearedcomments = true
  8880  }
  8881  
  8882  // CommentsCleared reports if the "comments" edge to the Comment entity was cleared.
  8883  func (m *UserMutation) CommentsCleared() bool {
  8884  	return m.clearedcomments
  8885  }
  8886  
  8887  // RemoveCommentIDs removes the "comments" edge to the Comment entity by IDs.
  8888  func (m *UserMutation) RemoveCommentIDs(ids ...int) {
  8889  	if m.removedcomments == nil {
  8890  		m.removedcomments = make(map[int]struct{})
  8891  	}
  8892  	for i := range ids {
  8893  		delete(m.comments, ids[i])
  8894  		m.removedcomments[ids[i]] = struct{}{}
  8895  	}
  8896  }
  8897  
  8898  // RemovedComments returns the removed IDs of the "comments" edge to the Comment entity.
  8899  func (m *UserMutation) RemovedCommentsIDs() (ids []int) {
  8900  	for id := range m.removedcomments {
  8901  		ids = append(ids, id)
  8902  	}
  8903  	return
  8904  }
  8905  
  8906  // CommentsIDs returns the "comments" edge IDs in the mutation.
  8907  func (m *UserMutation) CommentsIDs() (ids []int) {
  8908  	for id := range m.comments {
  8909  		ids = append(ids, id)
  8910  	}
  8911  	return
  8912  }
  8913  
  8914  // ResetComments resets all changes to the "comments" edge.
  8915  func (m *UserMutation) ResetComments() {
  8916  	m.comments = nil
  8917  	m.clearedcomments = false
  8918  	m.removedcomments = nil
  8919  }
  8920  
  8921  // AddRoleIDs adds the "roles" edge to the Role entity by ids.
  8922  func (m *UserMutation) AddRoleIDs(ids ...int) {
  8923  	if m.roles == nil {
  8924  		m.roles = make(map[int]struct{})
  8925  	}
  8926  	for i := range ids {
  8927  		m.roles[ids[i]] = struct{}{}
  8928  	}
  8929  }
  8930  
  8931  // ClearRoles clears the "roles" edge to the Role entity.
  8932  func (m *UserMutation) ClearRoles() {
  8933  	m.clearedroles = true
  8934  }
  8935  
  8936  // RolesCleared reports if the "roles" edge to the Role entity was cleared.
  8937  func (m *UserMutation) RolesCleared() bool {
  8938  	return m.clearedroles
  8939  }
  8940  
  8941  // RemoveRoleIDs removes the "roles" edge to the Role entity by IDs.
  8942  func (m *UserMutation) RemoveRoleIDs(ids ...int) {
  8943  	if m.removedroles == nil {
  8944  		m.removedroles = make(map[int]struct{})
  8945  	}
  8946  	for i := range ids {
  8947  		delete(m.roles, ids[i])
  8948  		m.removedroles[ids[i]] = struct{}{}
  8949  	}
  8950  }
  8951  
  8952  // RemovedRoles returns the removed IDs of the "roles" edge to the Role entity.
  8953  func (m *UserMutation) RemovedRolesIDs() (ids []int) {
  8954  	for id := range m.removedroles {
  8955  		ids = append(ids, id)
  8956  	}
  8957  	return
  8958  }
  8959  
  8960  // RolesIDs returns the "roles" edge IDs in the mutation.
  8961  func (m *UserMutation) RolesIDs() (ids []int) {
  8962  	for id := range m.roles {
  8963  		ids = append(ids, id)
  8964  	}
  8965  	return
  8966  }
  8967  
  8968  // ResetRoles resets all changes to the "roles" edge.
  8969  func (m *UserMutation) ResetRoles() {
  8970  	m.roles = nil
  8971  	m.clearedroles = false
  8972  	m.removedroles = nil
  8973  }
  8974  
  8975  // ClearAvatarImage clears the "avatar_image" edge to the File entity.
  8976  func (m *UserMutation) ClearAvatarImage() {
  8977  	m.clearedavatar_image = true
  8978  }
  8979  
  8980  // AvatarImageCleared reports if the "avatar_image" edge to the File entity was cleared.
  8981  func (m *UserMutation) AvatarImageCleared() bool {
  8982  	return m.AvatarImageIDCleared() || m.clearedavatar_image
  8983  }
  8984  
  8985  // AvatarImageIDs returns the "avatar_image" edge IDs in the mutation.
  8986  // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
  8987  // AvatarImageID instead. It exists only for internal usage by the builders.
  8988  func (m *UserMutation) AvatarImageIDs() (ids []int) {
  8989  	if id := m.avatar_image; id != nil {
  8990  		ids = append(ids, *id)
  8991  	}
  8992  	return
  8993  }
  8994  
  8995  // ResetAvatarImage resets all changes to the "avatar_image" edge.
  8996  func (m *UserMutation) ResetAvatarImage() {
  8997  	m.avatar_image = nil
  8998  	m.clearedavatar_image = false
  8999  }
  9000  
  9001  // Where appends a list predicates to the UserMutation builder.
  9002  func (m *UserMutation) Where(ps ...predicate.User) {
  9003  	m.predicates = append(m.predicates, ps...)
  9004  }
  9005  
  9006  // Op returns the operation name.
  9007  func (m *UserMutation) Op() Op {
  9008  	return m.op
  9009  }
  9010  
  9011  // Type returns the node type of this mutation (User).
  9012  func (m *UserMutation) Type() string {
  9013  	return m.typ
  9014  }
  9015  
  9016  // Fields returns all fields that were changed during this mutation. Note that in
  9017  // order to get all numeric fields that were incremented/decremented, call
  9018  // AddedFields().
  9019  func (m *UserMutation) Fields() []string {
  9020  	fields := make([]string, 0, 16)
  9021  	if m.created_at != nil {
  9022  		fields = append(fields, user.FieldCreatedAt)
  9023  	}
  9024  	if m.updated_at != nil {
  9025  		fields = append(fields, user.FieldUpdatedAt)
  9026  	}
  9027  	if m.deleted_at != nil {
  9028  		fields = append(fields, user.FieldDeletedAt)
  9029  	}
  9030  	if m.username != nil {
  9031  		fields = append(fields, user.FieldUsername)
  9032  	}
  9033  	if m.display_name != nil {
  9034  		fields = append(fields, user.FieldDisplayName)
  9035  	}
  9036  	if m.url != nil {
  9037  		fields = append(fields, user.FieldURL)
  9038  	}
  9039  	if m.provider != nil {
  9040  		fields = append(fields, user.FieldProvider)
  9041  	}
  9042  	if m.provider_id != nil {
  9043  		fields = append(fields, user.FieldProviderID)
  9044  	}
  9045  	if m.provider_username != nil {
  9046  		fields = append(fields, user.FieldProviderUsername)
  9047  	}
  9048  	if m.provider_avatar != nil {
  9049  		fields = append(fields, user.FieldProviderAvatar)
  9050  	}
  9051  	if m.email != nil {
  9052  		fields = append(fields, user.FieldEmail)
  9053  	}
  9054  	if m.password != nil {
  9055  		fields = append(fields, user.FieldPassword)
  9056  	}
  9057  	if m.bio != nil {
  9058  		fields = append(fields, user.FieldBio)
  9059  	}
  9060  	if m.bio_html != nil {
  9061  		fields = append(fields, user.FieldBioHTML)
  9062  	}
  9063  	if m.active != nil {
  9064  		fields = append(fields, user.FieldActive)
  9065  	}
  9066  	if m.avatar_image != nil {
  9067  		fields = append(fields, user.FieldAvatarImageID)
  9068  	}
  9069  	return fields
  9070  }
  9071  
  9072  // Field returns the value of a field with the given name. The second boolean
  9073  // return value indicates that this field was not set, or was not defined in the
  9074  // schema.
  9075  func (m *UserMutation) Field(name string) (ent.Value, bool) {
  9076  	switch name {
  9077  	case user.FieldCreatedAt:
  9078  		return m.CreatedAt()
  9079  	case user.FieldUpdatedAt:
  9080  		return m.UpdatedAt()
  9081  	case user.FieldDeletedAt:
  9082  		return m.DeletedAt()
  9083  	case user.FieldUsername:
  9084  		return m.Username()
  9085  	case user.FieldDisplayName:
  9086  		return m.DisplayName()
  9087  	case user.FieldURL:
  9088  		return m.URL()
  9089  	case user.FieldProvider:
  9090  		return m.Provider()
  9091  	case user.FieldProviderID:
  9092  		return m.ProviderID()
  9093  	case user.FieldProviderUsername:
  9094  		return m.ProviderUsername()
  9095  	case user.FieldProviderAvatar:
  9096  		return m.ProviderAvatar()
  9097  	case user.FieldEmail:
  9098  		return m.Email()
  9099  	case user.FieldPassword:
  9100  		return m.Password()
  9101  	case user.FieldBio:
  9102  		return m.Bio()
  9103  	case user.FieldBioHTML:
  9104  		return m.BioHTML()
  9105  	case user.FieldActive:
  9106  		return m.Active()
  9107  	case user.FieldAvatarImageID:
  9108  		return m.AvatarImageID()
  9109  	}
  9110  	return nil, false
  9111  }
  9112  
  9113  // OldField returns the old value of the field from the database. An error is
  9114  // returned if the mutation operation is not UpdateOne, or the query to the
  9115  // database failed.
  9116  func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
  9117  	switch name {
  9118  	case user.FieldCreatedAt:
  9119  		return m.OldCreatedAt(ctx)
  9120  	case user.FieldUpdatedAt:
  9121  		return m.OldUpdatedAt(ctx)
  9122  	case user.FieldDeletedAt:
  9123  		return m.OldDeletedAt(ctx)
  9124  	case user.FieldUsername:
  9125  		return m.OldUsername(ctx)
  9126  	case user.FieldDisplayName:
  9127  		return m.OldDisplayName(ctx)
  9128  	case user.FieldURL:
  9129  		return m.OldURL(ctx)
  9130  	case user.FieldProvider:
  9131  		return m.OldProvider(ctx)
  9132  	case user.FieldProviderID:
  9133  		return m.OldProviderID(ctx)
  9134  	case user.FieldProviderUsername:
  9135  		return m.OldProviderUsername(ctx)
  9136  	case user.FieldProviderAvatar:
  9137  		return m.OldProviderAvatar(ctx)
  9138  	case user.FieldEmail:
  9139  		return m.OldEmail(ctx)
  9140  	case user.FieldPassword:
  9141  		return m.OldPassword(ctx)
  9142  	case user.FieldBio:
  9143  		return m.OldBio(ctx)
  9144  	case user.FieldBioHTML:
  9145  		return m.OldBioHTML(ctx)
  9146  	case user.FieldActive:
  9147  		return m.OldActive(ctx)
  9148  	case user.FieldAvatarImageID:
  9149  		return m.OldAvatarImageID(ctx)
  9150  	}
  9151  	return nil, fmt.Errorf("unknown User field %s", name)
  9152  }
  9153  
  9154  // SetField sets the value of a field with the given name. It returns an error if
  9155  // the field is not defined in the schema, or if the type mismatched the field
  9156  // type.
  9157  func (m *UserMutation) SetField(name string, value ent.Value) error {
  9158  	switch name {
  9159  	case user.FieldCreatedAt:
  9160  		v, ok := value.(time.Time)
  9161  		if !ok {
  9162  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  9163  		}
  9164  		m.SetCreatedAt(v)
  9165  		return nil
  9166  	case user.FieldUpdatedAt:
  9167  		v, ok := value.(time.Time)
  9168  		if !ok {
  9169  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  9170  		}
  9171  		m.SetUpdatedAt(v)
  9172  		return nil
  9173  	case user.FieldDeletedAt:
  9174  		v, ok := value.(time.Time)
  9175  		if !ok {
  9176  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  9177  		}
  9178  		m.SetDeletedAt(v)
  9179  		return nil
  9180  	case user.FieldUsername:
  9181  		v, ok := value.(string)
  9182  		if !ok {
  9183  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  9184  		}
  9185  		m.SetUsername(v)
  9186  		return nil
  9187  	case user.FieldDisplayName:
  9188  		v, ok := value.(string)
  9189  		if !ok {
  9190  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  9191  		}
  9192  		m.SetDisplayName(v)
  9193  		return nil
  9194  	case user.FieldURL:
  9195  		v, ok := value.(string)
  9196  		if !ok {
  9197  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  9198  		}
  9199  		m.SetURL(v)
  9200  		return nil
  9201  	case user.FieldProvider:
  9202  		v, ok := value.(string)
  9203  		if !ok {
  9204  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  9205  		}
  9206  		m.SetProvider(v)
  9207  		return nil
  9208  	case user.FieldProviderID:
  9209  		v, ok := value.(string)
  9210  		if !ok {
  9211  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  9212  		}
  9213  		m.SetProviderID(v)
  9214  		return nil
  9215  	case user.FieldProviderUsername:
  9216  		v, ok := value.(string)
  9217  		if !ok {
  9218  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  9219  		}
  9220  		m.SetProviderUsername(v)
  9221  		return nil
  9222  	case user.FieldProviderAvatar:
  9223  		v, ok := value.(string)
  9224  		if !ok {
  9225  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  9226  		}
  9227  		m.SetProviderAvatar(v)
  9228  		return nil
  9229  	case user.FieldEmail:
  9230  		v, ok := value.(string)
  9231  		if !ok {
  9232  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  9233  		}
  9234  		m.SetEmail(v)
  9235  		return nil
  9236  	case user.FieldPassword:
  9237  		v, ok := value.(string)
  9238  		if !ok {
  9239  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  9240  		}
  9241  		m.SetPassword(v)
  9242  		return nil
  9243  	case user.FieldBio:
  9244  		v, ok := value.(string)
  9245  		if !ok {
  9246  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  9247  		}
  9248  		m.SetBio(v)
  9249  		return nil
  9250  	case user.FieldBioHTML:
  9251  		v, ok := value.(string)
  9252  		if !ok {
  9253  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  9254  		}
  9255  		m.SetBioHTML(v)
  9256  		return nil
  9257  	case user.FieldActive:
  9258  		v, ok := value.(bool)
  9259  		if !ok {
  9260  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  9261  		}
  9262  		m.SetActive(v)
  9263  		return nil
  9264  	case user.FieldAvatarImageID:
  9265  		v, ok := value.(int)
  9266  		if !ok {
  9267  			return fmt.Errorf("unexpected type %T for field %s", value, name)
  9268  		}
  9269  		m.SetAvatarImageID(v)
  9270  		return nil
  9271  	}
  9272  	return fmt.Errorf("unknown User field %s", name)
  9273  }
  9274  
  9275  // AddedFields returns all numeric fields that were incremented/decremented during
  9276  // this mutation.
  9277  func (m *UserMutation) AddedFields() []string {
  9278  	var fields []string
  9279  	return fields
  9280  }
  9281  
  9282  // AddedField returns the numeric value that was incremented/decremented on a field
  9283  // with the given name. The second boolean return value indicates that this field
  9284  // was not set, or was not defined in the schema.
  9285  func (m *UserMutation) AddedField(name string) (ent.Value, bool) {
  9286  	switch name {
  9287  	}
  9288  	return nil, false
  9289  }
  9290  
  9291  // AddField adds the value to the field with the given name. It returns an error if
  9292  // the field is not defined in the schema, or if the type mismatched the field
  9293  // type.
  9294  func (m *UserMutation) AddField(name string, value ent.Value) error {
  9295  	switch name {
  9296  	}
  9297  	return fmt.Errorf("unknown User numeric field %s", name)
  9298  }
  9299  
  9300  // ClearedFields returns all nullable fields that were cleared during this
  9301  // mutation.
  9302  func (m *UserMutation) ClearedFields() []string {
  9303  	var fields []string
  9304  	if m.FieldCleared(user.FieldDeletedAt) {
  9305  		fields = append(fields, user.FieldDeletedAt)
  9306  	}
  9307  	if m.FieldCleared(user.FieldDisplayName) {
  9308  		fields = append(fields, user.FieldDisplayName)
  9309  	}
  9310  	if m.FieldCleared(user.FieldURL) {
  9311  		fields = append(fields, user.FieldURL)
  9312  	}
  9313  	if m.FieldCleared(user.FieldProvider) {
  9314  		fields = append(fields, user.FieldProvider)
  9315  	}
  9316  	if m.FieldCleared(user.FieldProviderID) {
  9317  		fields = append(fields, user.FieldProviderID)
  9318  	}
  9319  	if m.FieldCleared(user.FieldProviderUsername) {
  9320  		fields = append(fields, user.FieldProviderUsername)
  9321  	}
  9322  	if m.FieldCleared(user.FieldProviderAvatar) {
  9323  		fields = append(fields, user.FieldProviderAvatar)
  9324  	}
  9325  	if m.FieldCleared(user.FieldEmail) {
  9326  		fields = append(fields, user.FieldEmail)
  9327  	}
  9328  	if m.FieldCleared(user.FieldPassword) {
  9329  		fields = append(fields, user.FieldPassword)
  9330  	}
  9331  	if m.FieldCleared(user.FieldBio) {
  9332  		fields = append(fields, user.FieldBio)
  9333  	}
  9334  	if m.FieldCleared(user.FieldBioHTML) {
  9335  		fields = append(fields, user.FieldBioHTML)
  9336  	}
  9337  	if m.FieldCleared(user.FieldAvatarImageID) {
  9338  		fields = append(fields, user.FieldAvatarImageID)
  9339  	}
  9340  	return fields
  9341  }
  9342  
  9343  // FieldCleared returns a boolean indicating if a field with the given name was
  9344  // cleared in this mutation.
  9345  func (m *UserMutation) FieldCleared(name string) bool {
  9346  	_, ok := m.clearedFields[name]
  9347  	return ok
  9348  }
  9349  
  9350  // ClearField clears the value of the field with the given name. It returns an
  9351  // error if the field is not defined in the schema.
  9352  func (m *UserMutation) ClearField(name string) error {
  9353  	switch name {
  9354  	case user.FieldDeletedAt:
  9355  		m.ClearDeletedAt()
  9356  		return nil
  9357  	case user.FieldDisplayName:
  9358  		m.ClearDisplayName()
  9359  		return nil
  9360  	case user.FieldURL:
  9361  		m.ClearURL()
  9362  		return nil
  9363  	case user.FieldProvider:
  9364  		m.ClearProvider()
  9365  		return nil
  9366  	case user.FieldProviderID:
  9367  		m.ClearProviderID()
  9368  		return nil
  9369  	case user.FieldProviderUsername:
  9370  		m.ClearProviderUsername()
  9371  		return nil
  9372  	case user.FieldProviderAvatar:
  9373  		m.ClearProviderAvatar()
  9374  		return nil
  9375  	case user.FieldEmail:
  9376  		m.ClearEmail()
  9377  		return nil
  9378  	case user.FieldPassword:
  9379  		m.ClearPassword()
  9380  		return nil
  9381  	case user.FieldBio:
  9382  		m.ClearBio()
  9383  		return nil
  9384  	case user.FieldBioHTML:
  9385  		m.ClearBioHTML()
  9386  		return nil
  9387  	case user.FieldAvatarImageID:
  9388  		m.ClearAvatarImageID()
  9389  		return nil
  9390  	}
  9391  	return fmt.Errorf("unknown User nullable field %s", name)
  9392  }
  9393  
  9394  // ResetField resets all changes in the mutation for the field with the given name.
  9395  // It returns an error if the field is not defined in the schema.
  9396  func (m *UserMutation) ResetField(name string) error {
  9397  	switch name {
  9398  	case user.FieldCreatedAt:
  9399  		m.ResetCreatedAt()
  9400  		return nil
  9401  	case user.FieldUpdatedAt:
  9402  		m.ResetUpdatedAt()
  9403  		return nil
  9404  	case user.FieldDeletedAt:
  9405  		m.ResetDeletedAt()
  9406  		return nil
  9407  	case user.FieldUsername:
  9408  		m.ResetUsername()
  9409  		return nil
  9410  	case user.FieldDisplayName:
  9411  		m.ResetDisplayName()
  9412  		return nil
  9413  	case user.FieldURL:
  9414  		m.ResetURL()
  9415  		return nil
  9416  	case user.FieldProvider:
  9417  		m.ResetProvider()
  9418  		return nil
  9419  	case user.FieldProviderID:
  9420  		m.ResetProviderID()
  9421  		return nil
  9422  	case user.FieldProviderUsername:
  9423  		m.ResetProviderUsername()
  9424  		return nil
  9425  	case user.FieldProviderAvatar:
  9426  		m.ResetProviderAvatar()
  9427  		return nil
  9428  	case user.FieldEmail:
  9429  		m.ResetEmail()
  9430  		return nil
  9431  	case user.FieldPassword:
  9432  		m.ResetPassword()
  9433  		return nil
  9434  	case user.FieldBio:
  9435  		m.ResetBio()
  9436  		return nil
  9437  	case user.FieldBioHTML:
  9438  		m.ResetBioHTML()
  9439  		return nil
  9440  	case user.FieldActive:
  9441  		m.ResetActive()
  9442  		return nil
  9443  	case user.FieldAvatarImageID:
  9444  		m.ResetAvatarImageID()
  9445  		return nil
  9446  	}
  9447  	return fmt.Errorf("unknown User field %s", name)
  9448  }
  9449  
  9450  // AddedEdges returns all edge names that were set/added in this mutation.
  9451  func (m *UserMutation) AddedEdges() []string {
  9452  	edges := make([]string, 0, 5)
  9453  	if m.posts != nil {
  9454  		edges = append(edges, user.EdgePosts)
  9455  	}
  9456  	if m.files != nil {
  9457  		edges = append(edges, user.EdgeFiles)
  9458  	}
  9459  	if m.comments != nil {
  9460  		edges = append(edges, user.EdgeComments)
  9461  	}
  9462  	if m.roles != nil {
  9463  		edges = append(edges, user.EdgeRoles)
  9464  	}
  9465  	if m.avatar_image != nil {
  9466  		edges = append(edges, user.EdgeAvatarImage)
  9467  	}
  9468  	return edges
  9469  }
  9470  
  9471  // AddedIDs returns all IDs (to other nodes) that were added for the given edge
  9472  // name in this mutation.
  9473  func (m *UserMutation) AddedIDs(name string) []ent.Value {
  9474  	switch name {
  9475  	case user.EdgePosts:
  9476  		ids := make([]ent.Value, 0, len(m.posts))
  9477  		for id := range m.posts {
  9478  			ids = append(ids, id)
  9479  		}
  9480  		return ids
  9481  	case user.EdgeFiles:
  9482  		ids := make([]ent.Value, 0, len(m.files))
  9483  		for id := range m.files {
  9484  			ids = append(ids, id)
  9485  		}
  9486  		return ids
  9487  	case user.EdgeComments:
  9488  		ids := make([]ent.Value, 0, len(m.comments))
  9489  		for id := range m.comments {
  9490  			ids = append(ids, id)
  9491  		}
  9492  		return ids
  9493  	case user.EdgeRoles:
  9494  		ids := make([]ent.Value, 0, len(m.roles))
  9495  		for id := range m.roles {
  9496  			ids = append(ids, id)
  9497  		}
  9498  		return ids
  9499  	case user.EdgeAvatarImage:
  9500  		if id := m.avatar_image; id != nil {
  9501  			return []ent.Value{*id}
  9502  		}
  9503  	}
  9504  	return nil
  9505  }
  9506  
  9507  // RemovedEdges returns all edge names that were removed in this mutation.
  9508  func (m *UserMutation) RemovedEdges() []string {
  9509  	edges := make([]string, 0, 5)
  9510  	if m.removedposts != nil {
  9511  		edges = append(edges, user.EdgePosts)
  9512  	}
  9513  	if m.removedfiles != nil {
  9514  		edges = append(edges, user.EdgeFiles)
  9515  	}
  9516  	if m.removedcomments != nil {
  9517  		edges = append(edges, user.EdgeComments)
  9518  	}
  9519  	if m.removedroles != nil {
  9520  		edges = append(edges, user.EdgeRoles)
  9521  	}
  9522  	return edges
  9523  }
  9524  
  9525  // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
  9526  // the given name in this mutation.
  9527  func (m *UserMutation) RemovedIDs(name string) []ent.Value {
  9528  	switch name {
  9529  	case user.EdgePosts:
  9530  		ids := make([]ent.Value, 0, len(m.removedposts))
  9531  		for id := range m.removedposts {
  9532  			ids = append(ids, id)
  9533  		}
  9534  		return ids
  9535  	case user.EdgeFiles:
  9536  		ids := make([]ent.Value, 0, len(m.removedfiles))
  9537  		for id := range m.removedfiles {
  9538  			ids = append(ids, id)
  9539  		}
  9540  		return ids
  9541  	case user.EdgeComments:
  9542  		ids := make([]ent.Value, 0, len(m.removedcomments))
  9543  		for id := range m.removedcomments {
  9544  			ids = append(ids, id)
  9545  		}
  9546  		return ids
  9547  	case user.EdgeRoles:
  9548  		ids := make([]ent.Value, 0, len(m.removedroles))
  9549  		for id := range m.removedroles {
  9550  			ids = append(ids, id)
  9551  		}
  9552  		return ids
  9553  	}
  9554  	return nil
  9555  }
  9556  
  9557  // ClearedEdges returns all edge names that were cleared in this mutation.
  9558  func (m *UserMutation) ClearedEdges() []string {
  9559  	edges := make([]string, 0, 5)
  9560  	if m.clearedposts {
  9561  		edges = append(edges, user.EdgePosts)
  9562  	}
  9563  	if m.clearedfiles {
  9564  		edges = append(edges, user.EdgeFiles)
  9565  	}
  9566  	if m.clearedcomments {
  9567  		edges = append(edges, user.EdgeComments)
  9568  	}
  9569  	if m.clearedroles {
  9570  		edges = append(edges, user.EdgeRoles)
  9571  	}
  9572  	if m.clearedavatar_image {
  9573  		edges = append(edges, user.EdgeAvatarImage)
  9574  	}
  9575  	return edges
  9576  }
  9577  
  9578  // EdgeCleared returns a boolean which indicates if the edge with the given name
  9579  // was cleared in this mutation.
  9580  func (m *UserMutation) EdgeCleared(name string) bool {
  9581  	switch name {
  9582  	case user.EdgePosts:
  9583  		return m.clearedposts
  9584  	case user.EdgeFiles:
  9585  		return m.clearedfiles
  9586  	case user.EdgeComments:
  9587  		return m.clearedcomments
  9588  	case user.EdgeRoles:
  9589  		return m.clearedroles
  9590  	case user.EdgeAvatarImage:
  9591  		return m.clearedavatar_image
  9592  	}
  9593  	return false
  9594  }
  9595  
  9596  // ClearEdge clears the value of the edge with the given name. It returns an error
  9597  // if that edge is not defined in the schema.
  9598  func (m *UserMutation) ClearEdge(name string) error {
  9599  	switch name {
  9600  	case user.EdgeAvatarImage:
  9601  		m.ClearAvatarImage()
  9602  		return nil
  9603  	}
  9604  	return fmt.Errorf("unknown User unique edge %s", name)
  9605  }
  9606  
  9607  // ResetEdge resets all changes to the edge with the given name in this mutation.
  9608  // It returns an error if the edge is not defined in the schema.
  9609  func (m *UserMutation) ResetEdge(name string) error {
  9610  	switch name {
  9611  	case user.EdgePosts:
  9612  		m.ResetPosts()
  9613  		return nil
  9614  	case user.EdgeFiles:
  9615  		m.ResetFiles()
  9616  		return nil
  9617  	case user.EdgeComments:
  9618  		m.ResetComments()
  9619  		return nil
  9620  	case user.EdgeRoles:
  9621  		m.ResetRoles()
  9622  		return nil
  9623  	case user.EdgeAvatarImage:
  9624  		m.ResetAvatarImage()
  9625  		return nil
  9626  	}
  9627  	return fmt.Errorf("unknown User edge %s", name)
  9628  }