// Code generated by ent, DO NOT EDIT.

package models

import (
	"fmt"
	"juwan-backend/app/community/rpc/internal/models/posts"
	"juwan-backend/pkg/types"
	"strings"
	"time"

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

// Posts is the model entity for the Posts schema.
type Posts struct {
	config `json:"-"`
	// ID of the ent.
	ID int64 `json:"id,omitempty"`
	// AuthorID holds the value of the "author_id" field.
	AuthorID int64 `json:"author_id,omitempty"`
	// AuthorRole holds the value of the "author_role" field.
	AuthorRole string `json:"author_role,omitempty"`
	// Title holds the value of the "title" field.
	Title string `json:"title,omitempty"`
	// Content holds the value of the "content" field.
	Content string `json:"content,omitempty"`
	// Images holds the value of the "images" field.
	Images types.TextArray `json:"images,omitempty"`
	// Tags holds the value of the "tags" field.
	Tags types.TextArray `json:"tags,omitempty"`
	// LinkedOrderID holds the value of the "linked_order_id" field.
	LinkedOrderID *int64 `json:"linked_order_id,omitempty"`
	// QuotedPostID holds the value of the "quoted_post_id" field.
	QuotedPostID *int64 `json:"quoted_post_id,omitempty"`
	// LikeCount holds the value of the "like_count" field.
	LikeCount int `json:"like_count,omitempty"`
	// CommentCount holds the value of the "comment_count" field.
	CommentCount int `json:"comment_count,omitempty"`
	// Pinned holds the value of the "pinned" field.
	Pinned bool `json:"pinned,omitempty"`
	// CreatedAt holds the value of the "created_at" field.
	CreatedAt time.Time `json:"created_at,omitempty"`
	// UpdatedAt holds the value of the "updated_at" field.
	UpdatedAt time.Time `json:"updated_at,omitempty"`
	// DeletedAt holds the value of the "deleted_at" field.
	DeletedAt    *time.Time `json:"deleted_at,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*Posts) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case posts.FieldPinned:
			values[i] = new(sql.NullBool)
		case posts.FieldID, posts.FieldAuthorID, posts.FieldLinkedOrderID, posts.FieldQuotedPostID, posts.FieldLikeCount, posts.FieldCommentCount:
			values[i] = new(sql.NullInt64)
		case posts.FieldAuthorRole, posts.FieldTitle, posts.FieldContent:
			values[i] = new(sql.NullString)
		case posts.FieldCreatedAt, posts.FieldUpdatedAt, posts.FieldDeletedAt:
			values[i] = new(sql.NullTime)
		case posts.FieldImages, posts.FieldTags:
			values[i] = new(types.TextArray)
		default:
			values[i] = new(sql.UnknownType)
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Posts fields.
func (_m *Posts) assignValues(columns []string, values []any) error {
	if m, n := len(values), len(columns); m < n {
		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
	}
	for i := range columns {
		switch columns[i] {
		case posts.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			_m.ID = int64(value.Int64)
		case posts.FieldAuthorID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field author_id", values[i])
			} else if value.Valid {
				_m.AuthorID = value.Int64
			}
		case posts.FieldAuthorRole:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field author_role", values[i])
			} else if value.Valid {
				_m.AuthorRole = value.String
			}
		case posts.FieldTitle:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field title", values[i])
			} else if value.Valid {
				_m.Title = value.String
			}
		case posts.FieldContent:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field content", values[i])
			} else if value.Valid {
				_m.Content = value.String
			}
		case posts.FieldImages:
			if value, ok := values[i].(*types.TextArray); !ok {
				return fmt.Errorf("unexpected type %T for field images", values[i])
			} else if value != nil {
				_m.Images = *value
			}
		case posts.FieldTags:
			if value, ok := values[i].(*types.TextArray); !ok {
				return fmt.Errorf("unexpected type %T for field tags", values[i])
			} else if value != nil {
				_m.Tags = *value
			}
		case posts.FieldLinkedOrderID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field linked_order_id", values[i])
			} else if value.Valid {
				_m.LinkedOrderID = new(int64)
				*_m.LinkedOrderID = value.Int64
			}
		case posts.FieldQuotedPostID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field quoted_post_id", values[i])
			} else if value.Valid {
				_m.QuotedPostID = new(int64)
				*_m.QuotedPostID = value.Int64
			}
		case posts.FieldLikeCount:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field like_count", values[i])
			} else if value.Valid {
				_m.LikeCount = int(value.Int64)
			}
		case posts.FieldCommentCount:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field comment_count", values[i])
			} else if value.Valid {
				_m.CommentCount = int(value.Int64)
			}
		case posts.FieldPinned:
			if value, ok := values[i].(*sql.NullBool); !ok {
				return fmt.Errorf("unexpected type %T for field pinned", values[i])
			} else if value.Valid {
				_m.Pinned = value.Bool
			}
		case posts.FieldCreatedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field created_at", values[i])
			} else if value.Valid {
				_m.CreatedAt = value.Time
			}
		case posts.FieldUpdatedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field updated_at", values[i])
			} else if value.Valid {
				_m.UpdatedAt = value.Time
			}
		case posts.FieldDeletedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
			} else if value.Valid {
				_m.DeletedAt = new(time.Time)
				*_m.DeletedAt = value.Time
			}
		default:
			_m.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

// Value returns the ent.Value that was dynamically selected and assigned to the Posts.
// This includes values selected through modifiers, order, etc.
func (_m *Posts) Value(name string) (ent.Value, error) {
	return _m.selectValues.Get(name)
}

// Update returns a builder for updating this Posts.
// Note that you need to call Posts.Unwrap() before calling this method if this Posts
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *Posts) Update() *PostsUpdateOne {
	return NewPostsClient(_m.config).UpdateOne(_m)
}

// Unwrap unwraps the Posts entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (_m *Posts) Unwrap() *Posts {
	_tx, ok := _m.config.driver.(*txDriver)
	if !ok {
		panic("models: Posts is not a transactional entity")
	}
	_m.config.driver = _tx.drv
	return _m
}

// String implements the fmt.Stringer.
func (_m *Posts) String() string {
	var builder strings.Builder
	builder.WriteString("Posts(")
	builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
	builder.WriteString("author_id=")
	builder.WriteString(fmt.Sprintf("%v", _m.AuthorID))
	builder.WriteString(", ")
	builder.WriteString("author_role=")
	builder.WriteString(_m.AuthorRole)
	builder.WriteString(", ")
	builder.WriteString("title=")
	builder.WriteString(_m.Title)
	builder.WriteString(", ")
	builder.WriteString("content=")
	builder.WriteString(_m.Content)
	builder.WriteString(", ")
	builder.WriteString("images=")
	builder.WriteString(fmt.Sprintf("%v", _m.Images))
	builder.WriteString(", ")
	builder.WriteString("tags=")
	builder.WriteString(fmt.Sprintf("%v", _m.Tags))
	builder.WriteString(", ")
	if v := _m.LinkedOrderID; v != nil {
		builder.WriteString("linked_order_id=")
		builder.WriteString(fmt.Sprintf("%v", *v))
	}
	builder.WriteString(", ")
	if v := _m.QuotedPostID; v != nil {
		builder.WriteString("quoted_post_id=")
		builder.WriteString(fmt.Sprintf("%v", *v))
	}
	builder.WriteString(", ")
	builder.WriteString("like_count=")
	builder.WriteString(fmt.Sprintf("%v", _m.LikeCount))
	builder.WriteString(", ")
	builder.WriteString("comment_count=")
	builder.WriteString(fmt.Sprintf("%v", _m.CommentCount))
	builder.WriteString(", ")
	builder.WriteString("pinned=")
	builder.WriteString(fmt.Sprintf("%v", _m.Pinned))
	builder.WriteString(", ")
	builder.WriteString("created_at=")
	builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	if v := _m.DeletedAt; v != nil {
		builder.WriteString("deleted_at=")
		builder.WriteString(v.Format(time.ANSIC))
	}
	builder.WriteByte(')')
	return builder.String()
}

// PostsSlice is a parsable slice of Posts.
type PostsSlice []*Posts
