func (m *BlogPostMutation) ClearEdge(name string) error {
	switch name {
	case blogpost.EdgeAuthor:
		m.ClearAuthor()
		return nil
	}
	return fmt.Errorf("unknown BlogPost unique edge %s", name)
}
ClearEdge clears the value of the edge with the given name. It returns an error
if that edge is not defined in the schema.
package ent
import (
	"context"
	"fmt"
	"sync"
	"time"
	"entgo.io/contrib/entproto/internal/entprototest/ent/blogpost"
	"entgo.io/contrib/entproto/internal/entprototest/ent/category"
	"entgo.io/contrib/entproto/internal/entprototest/ent/dependsonskipped"
	"entgo.io/contrib/entproto/internal/entprototest/ent/duplicatenumbermessage"
	"entgo.io/contrib/entproto/internal/entprototest/ent/image"
	"entgo.io/contrib/entproto/internal/entprototest/ent/invalidfieldmessage"
	"entgo.io/contrib/entproto/internal/entprototest/ent/messagewithenum"
	"entgo.io/contrib/entproto/internal/entprototest/ent/messagewithfieldone"
	"entgo.io/contrib/entproto/internal/entprototest/ent/messagewithoptionals"
	"entgo.io/contrib/entproto/internal/entprototest/ent/messagewithpackagename"
	"entgo.io/contrib/entproto/internal/entprototest/ent/portal"
	"entgo.io/contrib/entproto/internal/entprototest/ent/predicate"
	"entgo.io/contrib/entproto/internal/entprototest/ent/schema"
	"entgo.io/contrib/entproto/internal/entprototest/ent/user"
	"entgo.io/contrib/entproto/internal/entprototest/ent/validmessage"
	"github.com/google/uuid"
	"entgo.io/ent"
)
const (
	OpCreate    = ent.OpCreate
	OpDelete    = ent.OpDelete
	OpDeleteOne = ent.OpDeleteOne
	OpUpdate    = ent.OpUpdate
	OpUpdateOne = ent.OpUpdateOne
	TypeBlogPost               = "BlogPost"
	TypeCategory               = "Category"
	TypeDependsOnSkipped       = "DependsOnSkipped"
	TypeDuplicateNumberMessage = "DuplicateNumberMessage"
	TypeExplicitSkippedMessage = "ExplicitSkippedMessage"
	TypeImage                  = "Image"
	TypeImplicitSkippedMessage = "ImplicitSkippedMessage"
	TypeInvalidFieldMessage    = "InvalidFieldMessage"
	TypeMessageWithEnum        = "MessageWithEnum"
	TypeMessageWithFieldOne    = "MessageWithFieldOne"
	TypeMessageWithID          = "MessageWithID"
	TypeMessageWithOptionals   = "MessageWithOptionals"
	TypeMessageWithPackageName = "MessageWithPackageName"
	TypePortal                 = "Portal"
	TypeUser                   = "User"
	TypeValidMessage           = "ValidMessage"
)
type BlogPostMutation struct {
	config
	op                Op
	typ               string
	id                *int
	title             *string
	body              *string
	external_id       *int
	addexternal_id    *int
	clearedFields     map[string]struct{}
	author            *int
	clearedauthor     bool
	categories        map[int]struct{}
	removedcategories map[int]struct{}
	clearedcategories bool
	done              bool
	oldValue          func(context.Context) (*BlogPost, error)
	predicates        []predicate.BlogPost
}
var _ ent.Mutation = (*BlogPostMutation)(nil)
type blogpostOption func(*BlogPostMutation)
func newBlogPostMutation(c config, op Op, opts ...blogpostOption) *BlogPostMutation {
	m := &BlogPostMutation{
		config:        c,
		op:            op,
		typ:           TypeBlogPost,
		clearedFields: make(map[string]struct{}),
	}
	for _, opt := range opts {
		opt(m)
	}
	return m
}
func withBlogPostID(id int) blogpostOption {
	return func(m *BlogPostMutation) {
		var (
			err   error
			once  sync.Once
			value *BlogPost
		)
		m.oldValue = func(ctx context.Context) (*BlogPost, error) {
			once.Do(func() {
				if m.done {
					err = fmt.Errorf("querying old values post mutation is not allowed")
				} else {
					value, err = m.Client().BlogPost.Get(ctx, id)
				}
			})
			return value, err
		}
		m.id = &id
	}
}
func withBlogPost(node *BlogPost) blogpostOption {
	return func(m *BlogPostMutation) {
		m.oldValue = func(context.Context) (*BlogPost, error) {
			return node, nil
		}
		m.id = &node.ID
	}
}
func (m BlogPostMutation) Client() *Client {
	client := &Client{config: m.config}
	client.init()
	return client
}
func (m BlogPostMutation) Tx() (*Tx, error) {
	if _, ok := m.driver.(*txDriver); !ok {
		return nil, fmt.Errorf("ent: mutation is not running in a transaction")
	}
	tx := &Tx{config: m.config}
	tx.init()
	return tx, nil
}
func (m *BlogPostMutation) ID() (id int, exists bool) {
	if m.id == nil {
		return
	}
	return *m.id, true
}
func (m *BlogPostMutation) SetTitle(s string) {
	m.title = &s
}
func (m *BlogPostMutation) Title() (r string, exists bool) {
	v := m.title
	if v == nil {
		return
	}
	return *v, true
}
func (m *BlogPostMutation) OldTitle(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, fmt.Errorf("OldTitle is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, fmt.Errorf("OldTitle requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldTitle: %w", err)
	}
	return oldValue.Title, nil
}
func (m *BlogPostMutation) ResetTitle() {
	m.title = nil
}
func (m *BlogPostMutation) SetBody(s string) {
	m.body = &s
}
func (m *BlogPostMutation) Body() (r string, exists bool) {
	v := m.body
	if v == nil {
		return
	}
	return *v, true
}
func (m *BlogPostMutation) OldBody(ctx context.Context) (v string, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, fmt.Errorf("OldBody is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, fmt.Errorf("OldBody requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldBody: %w", err)
	}
	return oldValue.Body, nil
}
func (m *BlogPostMutation) ResetBody() {
	m.body = nil
}
func (m *BlogPostMutation) SetExternalID(i int) {
	m.external_id = &i
	m.addexternal_id = nil
}
func (m *BlogPostMutation) ExternalID() (r int, exists bool) {
	v := m.external_id
	if v == nil {
		return
	}
	return *v, true
}
func (m *BlogPostMutation) OldExternalID(ctx context.Context) (v int, err error) {
	if !m.op.Is(OpUpdateOne) {
		return v, fmt.Errorf("OldExternalID is only allowed on UpdateOne operations")
	}
	if m.id == nil || m.oldValue == nil {
		return v, fmt.Errorf("OldExternalID requires an ID field in the mutation")
	}
	oldValue, err := m.oldValue(ctx)
	if err != nil {
		return v, fmt.Errorf("querying old value for OldExternalID: %w", err)
	}
	return oldValue.ExternalID, nil
}
func (m *BlogPostMutation) AddExternalID(i int) {
	if m.addexternal_id != nil {
		*m.addexternal_id += i
	} else {
		m.addexternal_id = &i
	}
}
func (m *BlogPostMutation) AddedExternalID() (r int, exists bool) {
	v := m.addexternal_id
	if v == nil {
		return
	}
	return *v, true
}
func (m *BlogPostMutation) ResetExternalID() {
	m.external_id = nil
	m.addexternal_id = nil
}
func (m *BlogPostMutation) SetAuthorID(id int) {
	m.author = &id
}
func (m *BlogPostMutation) ClearAuthor() {
	m.clearedauthor = true
}
func (m *BlogPostMutation) AuthorCleared() bool {
	return m.clearedauthor
}
func (m *BlogPostMutation) AuthorID() (id int, exists bool) {
	if m.author != nil {
		return *m.author, true
	}
	return
}
func (m *BlogPostMutation) AuthorIDs() (ids []int) {
	if id := m.author; id != nil {
		ids = append(ids, *id)
	}
	return
}
func (m *BlogPostMutation) ResetAuthor() {
	m.author = nil
	m.clearedauthor = false
}
func (m *BlogPostMutation) AddCategoryIDs(ids ...int) {
	if m.categories == nil {
		m.categories = make(map[int]struct{})
	}
	for i := range ids {
		m.categories[ids[i]] = struct{}{}
	}
}
func (m *BlogPostMutation) ClearCategories() {
	m.clearedcategories = true
}
func (m *BlogPostMutation) CategoriesCleared() bool {
	return m.clearedcategories
}
func (m *BlogPostMutation) RemoveCategoryIDs(ids ...int) {
	if m.removedcategories == nil {
		m.removedcategories = make(map[int]struct{})
	}
	for i := range ids {
		delete(m.categories, ids[i])
		m.removedcategories[ids[i]] = struct{}{}
	}
}
func (m *BlogPostMutation) RemovedCategoriesIDs() (ids []int) {
	for id := range m.removedcategories {
		ids = append(ids, id)
	}
	return
}
func (m *BlogPostMutation) CategoriesIDs() (ids []int) {
	for id := range m.categories {
		ids = append(ids, id)
	}
	return
}
func (m *BlogPostMutation) ResetCategories() {
	m.categories = nil
	m.clearedcategories = false
	m.removedcategories = nil
}
func (m *BlogPostMutation) Where(ps ...predicate.BlogPost) {
	m.predicates = append(m.predicates, ps...)
}
func (m *BlogPostMutation) Op() Op {
	return m.op
}
func (m *BlogPostMutation) Type() string {
	return m.typ
}
func (m *BlogPostMutation) Fields() []string {
	fields := make([]string, 0, 3)
	if m.title != nil {
		fields = append(fields, blogpost.FieldTitle)
	}
	if m.body != nil {
		fields = append(fields, blogpost.FieldBody)
	}
	if m.external_id != nil {
		fields = append(fields, blogpost.FieldExternalID)
	}
	return fields
}
func (m *BlogPostMutation) Field(name string) (ent.Value, bool) {
	switch name {
	case blogpost.FieldTitle:
		return m.Title()
	case blogpost.FieldBody:
		return m.Body()
	case blogpost.FieldExternalID:
		return m.ExternalID()
	}
	return nil, false
}
func (m *BlogPostMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
	switch name {
	case blogpost.FieldTitle:
		return m.OldTitle(ctx)
	case blogpost.FieldBody:
		return m.OldBody(ctx)
	case blogpost.FieldExternalID:
		return m.OldExternalID(ctx)
	}
	return nil, fmt.Errorf("unknown BlogPost field %s", name)
}
func (m *BlogPostMutation) SetField(name string, value ent.Value) error {
	switch name {
	case blogpost.FieldTitle:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetTitle(v)
		return nil
	case blogpost.FieldBody:
		v, ok := value.(string)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetBody(v)
		return nil
	case blogpost.FieldExternalID:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.SetExternalID(v)
		return nil
	}
	return fmt.Errorf("unknown BlogPost field %s", name)
}
func (m *BlogPostMutation) AddedFields() []string {
	var fields []string
	if m.addexternal_id != nil {
		fields = append(fields, blogpost.FieldExternalID)
	}
	return fields
}
func (m *BlogPostMutation) AddedField(name string) (ent.Value, bool) {
	switch name {
	case blogpost.FieldExternalID:
		return m.AddedExternalID()
	}
	return nil, false
}
func (m *BlogPostMutation) AddField(name string, value ent.Value) error {
	switch name {
	case blogpost.FieldExternalID:
		v, ok := value.(int)
		if !ok {
			return fmt.Errorf("unexpected type %T for field %s", value, name)
		}
		m.AddExternalID(v)
		return nil
	}
	return fmt.Errorf("unknown BlogPost numeric field %s", name)
}
func (m *BlogPostMutation) ClearedFields() []string {
	return nil
}
func (m *BlogPostMutation) FieldCleared(name string) bool {
	_, ok := m.clearedFields[name]
	return ok
}
func (m *BlogPostMutation) ClearField(name string) error {
	return fmt.Errorf("unknown BlogPost nullable field %s", name)
}
func (m *BlogPostMutation) ResetField(name string) error {
	switch name {
	case blogpost.FieldTitle:
		m.ResetTitle()
		return nil
	case blogpost.FieldBody:
		m.ResetBody()
		return nil
	case blogpost.FieldExternalID:
		m.ResetExternalID()
		return nil
	}
	return fmt.Errorf("unknown BlogPost field %s", name)
}
func (m *BlogPostMutation) AddedEdges() []string {
	edges := make([]string, 0, 2)
	if m.author != nil {
		edges = append(edges, blogpost.EdgeAuthor)
	}
	if m.categories != nil {
		edges = append(edges, blogpost.EdgeCategories)
	}
	return edges
}
func (m *BlogPostMutation) AddedIDs(name string) []ent.Value {
	switch name {
	case blogpost.EdgeAuthor:
		if id := m.author; id != nil {
			return []ent.Value{*id}
		}
	case blogpost.EdgeCategories:
		ids := make([]ent.Value, 0, len(m.categories))
		for id := range m.categories {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}
func (m *BlogPostMutation) RemovedEdges() []string {
	edges := make([]string, 0, 2)
	if m.removedcategories != nil {
		edges = append(edges, blogpost.EdgeCategories)
	}
	return edges
}
func (m *BlogPostMutation) RemovedIDs(name string) []ent.Value {
	switch name {
	case blogpost.EdgeCategories:
		ids := make([]ent.Value, 0, len(m.removedcategories))
		for id := range m.removedcategories {
			ids = append(ids, id)
		}
		return ids
	}
	return nil
}
func (m *BlogPostMutation) ClearedEdges() []string {
	edges := make([]string, 0, 2)
	if m.clearedauthor {
		edges = append(edges, blogpost.EdgeAuthor)
	}
	if m.clearedcategories {
		edges = append(edges, blogpost.EdgeCategories)
	}
	return edges
}
func (m *BlogPostMutation) EdgeCleared(name string) bool {
	switch name {
	case blogpost.EdgeAuthor:
		return m.clearedauthor
	case blogpost.EdgeCategories:
		return m.clearedcategories
	}
	return false
}