// Code generated by ent, DO NOT EDIT.

package ent

import (
	"encoding/json"
	"fmt"
	"strings"
	"time"
	"wechat-api/ent/labeltagging"

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

// LabelTagging is the model entity for the LabelTagging schema.
type LabelTagging struct {
	config `json:"-"`
	// ID of the ent.
	ID uint64 `json:"id,omitempty"`
	// Create Time | 创建日期
	CreatedAt time.Time `json:"created_at,omitempty"`
	// Update Time | 修改日期
	UpdatedAt time.Time `json:"updated_at,omitempty"`
	// Status 1: normal 2: ban | 状态 1 正常 2 禁用
	Status uint8 `json:"status,omitempty"`
	// Delete Time | 删除日期
	DeletedAt time.Time `json:"deleted_at,omitempty"`
	// 机构 ID
	OrganizationID uint64 `json:"organization_id,omitempty"`
	// 标签类型:1好友,2群组,3公众号,4企业微信联系人
	Type int `json:"type,omitempty"`
	// 关键词
	Conditions string `json:"conditions,omitempty"`
	// 命中后需要打的标签
	ActionLabelAdd []uint64 `json:"action_label_add,omitempty"`
	// 命中后需要移除的标签
	ActionLabelDel []uint64 `json:"action_label_del,omitempty"`
	selectValues   sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*LabelTagging) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case labeltagging.FieldActionLabelAdd, labeltagging.FieldActionLabelDel:
			values[i] = new([]byte)
		case labeltagging.FieldID, labeltagging.FieldStatus, labeltagging.FieldOrganizationID, labeltagging.FieldType:
			values[i] = new(sql.NullInt64)
		case labeltagging.FieldConditions:
			values[i] = new(sql.NullString)
		case labeltagging.FieldCreatedAt, labeltagging.FieldUpdatedAt, labeltagging.FieldDeletedAt:
			values[i] = new(sql.NullTime)
		default:
			values[i] = new(sql.UnknownType)
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the LabelTagging fields.
func (lt *LabelTagging) 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 labeltagging.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			lt.ID = uint64(value.Int64)
		case labeltagging.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 {
				lt.CreatedAt = value.Time
			}
		case labeltagging.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 {
				lt.UpdatedAt = value.Time
			}
		case labeltagging.FieldStatus:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				lt.Status = uint8(value.Int64)
			}
		case labeltagging.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 {
				lt.DeletedAt = value.Time
			}
		case labeltagging.FieldOrganizationID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field organization_id", values[i])
			} else if value.Valid {
				lt.OrganizationID = uint64(value.Int64)
			}
		case labeltagging.FieldType:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field type", values[i])
			} else if value.Valid {
				lt.Type = int(value.Int64)
			}
		case labeltagging.FieldConditions:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field conditions", values[i])
			} else if value.Valid {
				lt.Conditions = value.String
			}
		case labeltagging.FieldActionLabelAdd:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field action_label_add", values[i])
			} else if value != nil && len(*value) > 0 {
				if err := json.Unmarshal(*value, &lt.ActionLabelAdd); err != nil {
					return fmt.Errorf("unmarshal field action_label_add: %w", err)
				}
			}
		case labeltagging.FieldActionLabelDel:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field action_label_del", values[i])
			} else if value != nil && len(*value) > 0 {
				if err := json.Unmarshal(*value, &lt.ActionLabelDel); err != nil {
					return fmt.Errorf("unmarshal field action_label_del: %w", err)
				}
			}
		default:
			lt.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

// Unwrap unwraps the LabelTagging 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 (lt *LabelTagging) Unwrap() *LabelTagging {
	_tx, ok := lt.config.driver.(*txDriver)
	if !ok {
		panic("ent: LabelTagging is not a transactional entity")
	}
	lt.config.driver = _tx.drv
	return lt
}

// String implements the fmt.Stringer.
func (lt *LabelTagging) String() string {
	var builder strings.Builder
	builder.WriteString("LabelTagging(")
	builder.WriteString(fmt.Sprintf("id=%v, ", lt.ID))
	builder.WriteString("created_at=")
	builder.WriteString(lt.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(lt.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(fmt.Sprintf("%v", lt.Status))
	builder.WriteString(", ")
	builder.WriteString("deleted_at=")
	builder.WriteString(lt.DeletedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("organization_id=")
	builder.WriteString(fmt.Sprintf("%v", lt.OrganizationID))
	builder.WriteString(", ")
	builder.WriteString("type=")
	builder.WriteString(fmt.Sprintf("%v", lt.Type))
	builder.WriteString(", ")
	builder.WriteString("conditions=")
	builder.WriteString(lt.Conditions)
	builder.WriteString(", ")
	builder.WriteString("action_label_add=")
	builder.WriteString(fmt.Sprintf("%v", lt.ActionLabelAdd))
	builder.WriteString(", ")
	builder.WriteString("action_label_del=")
	builder.WriteString(fmt.Sprintf("%v", lt.ActionLabelDel))
	builder.WriteByte(')')
	return builder.String()
}

// LabelTaggings is a parsable slice of LabelTagging.
type LabelTaggings []*LabelTagging