// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"
	"time"
	"wechat-api/ent/batchmsg"

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

// BatchMsg is the model entity for the BatchMsg schema.
type BatchMsg 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"`
	// Delete Time | 删除日期
	DeletedAt time.Time `json:"deleted_at,omitempty"`
	// 状态 0 未开始 1 开始发送 2 发送完成 3 发送中止
	Status uint8 `json:"status,omitempty"`
	// 批次号
	BatchNo string `json:"batch_no,omitempty"`
	// 任务名称
	TaskName string `json:"task_name,omitempty"`
	// 发送方微信ID
	Fromwxid string `json:"fromwxid,omitempty"`
	// 内容
	Msg string `json:"msg,omitempty"`
	// 发送规则 all 全部 tag1,tag2 按tag发送
	Tag string `json:"tag,omitempty"`
	// 要发送的tagids
	Tagids string `json:"tagids,omitempty"`
	// 总数
	Total int32 `json:"total,omitempty"`
	// 成功数量
	Success int32 `json:"success,omitempty"`
	// 失败数量
	Fail int32 `json:"fail,omitempty"`
	// 开始时间
	StartTime time.Time `json:"start_time,omitempty"`
	// 结束时间
	StopTime time.Time `json:"stop_time,omitempty"`
	// 发送时间
	SendTime time.Time `json:"send_time,omitempty"`
	// 发送类型 1-群发消息 2-群发朋友圈
	Type int32 `json:"type,omitempty"`
	// organization_id | 租户ID
	OrganizationID uint64 `json:"organization_id,omitempty"`
	// 内容类型:1-微信 2-whatsapp
	Ctype uint64 `json:"ctype,omitempty"`
	// 国家区号
	Cc string `json:"cc,omitempty"`
	// 手机号
	Phone string `json:"phone,omitempty"`
	// 模板名
	TemplateName string `json:"template_name,omitempty"`
	// 模板code
	TemplateCode string `json:"template_code,omitempty"`
	// 语言
	Lang         string `json:"lang,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*BatchMsg) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case batchmsg.FieldID, batchmsg.FieldStatus, batchmsg.FieldTotal, batchmsg.FieldSuccess, batchmsg.FieldFail, batchmsg.FieldType, batchmsg.FieldOrganizationID, batchmsg.FieldCtype:
			values[i] = new(sql.NullInt64)
		case batchmsg.FieldBatchNo, batchmsg.FieldTaskName, batchmsg.FieldFromwxid, batchmsg.FieldMsg, batchmsg.FieldTag, batchmsg.FieldTagids, batchmsg.FieldCc, batchmsg.FieldPhone, batchmsg.FieldTemplateName, batchmsg.FieldTemplateCode, batchmsg.FieldLang:
			values[i] = new(sql.NullString)
		case batchmsg.FieldCreatedAt, batchmsg.FieldUpdatedAt, batchmsg.FieldDeletedAt, batchmsg.FieldStartTime, batchmsg.FieldStopTime, batchmsg.FieldSendTime:
			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 BatchMsg fields.
func (bm *BatchMsg) 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 batchmsg.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			bm.ID = uint64(value.Int64)
		case batchmsg.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 {
				bm.CreatedAt = value.Time
			}
		case batchmsg.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 {
				bm.UpdatedAt = value.Time
			}
		case batchmsg.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 {
				bm.DeletedAt = value.Time
			}
		case batchmsg.FieldStatus:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				bm.Status = uint8(value.Int64)
			}
		case batchmsg.FieldBatchNo:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field batch_no", values[i])
			} else if value.Valid {
				bm.BatchNo = value.String
			}
		case batchmsg.FieldTaskName:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field task_name", values[i])
			} else if value.Valid {
				bm.TaskName = value.String
			}
		case batchmsg.FieldFromwxid:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field fromwxid", values[i])
			} else if value.Valid {
				bm.Fromwxid = value.String
			}
		case batchmsg.FieldMsg:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field msg", values[i])
			} else if value.Valid {
				bm.Msg = value.String
			}
		case batchmsg.FieldTag:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field tag", values[i])
			} else if value.Valid {
				bm.Tag = value.String
			}
		case batchmsg.FieldTagids:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field tagids", values[i])
			} else if value.Valid {
				bm.Tagids = value.String
			}
		case batchmsg.FieldTotal:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field total", values[i])
			} else if value.Valid {
				bm.Total = int32(value.Int64)
			}
		case batchmsg.FieldSuccess:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field success", values[i])
			} else if value.Valid {
				bm.Success = int32(value.Int64)
			}
		case batchmsg.FieldFail:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field fail", values[i])
			} else if value.Valid {
				bm.Fail = int32(value.Int64)
			}
		case batchmsg.FieldStartTime:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field start_time", values[i])
			} else if value.Valid {
				bm.StartTime = value.Time
			}
		case batchmsg.FieldStopTime:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field stop_time", values[i])
			} else if value.Valid {
				bm.StopTime = value.Time
			}
		case batchmsg.FieldSendTime:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field send_time", values[i])
			} else if value.Valid {
				bm.SendTime = value.Time
			}
		case batchmsg.FieldType:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field type", values[i])
			} else if value.Valid {
				bm.Type = int32(value.Int64)
			}
		case batchmsg.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 {
				bm.OrganizationID = uint64(value.Int64)
			}
		case batchmsg.FieldCtype:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field ctype", values[i])
			} else if value.Valid {
				bm.Ctype = uint64(value.Int64)
			}
		case batchmsg.FieldCc:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field cc", values[i])
			} else if value.Valid {
				bm.Cc = value.String
			}
		case batchmsg.FieldPhone:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field phone", values[i])
			} else if value.Valid {
				bm.Phone = value.String
			}
		case batchmsg.FieldTemplateName:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field template_name", values[i])
			} else if value.Valid {
				bm.TemplateName = value.String
			}
		case batchmsg.FieldTemplateCode:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field template_code", values[i])
			} else if value.Valid {
				bm.TemplateCode = value.String
			}
		case batchmsg.FieldLang:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field lang", values[i])
			} else if value.Valid {
				bm.Lang = value.String
			}
		default:
			bm.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (bm *BatchMsg) String() string {
	var builder strings.Builder
	builder.WriteString("BatchMsg(")
	builder.WriteString(fmt.Sprintf("id=%v, ", bm.ID))
	builder.WriteString("created_at=")
	builder.WriteString(bm.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(bm.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("deleted_at=")
	builder.WriteString(bm.DeletedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(fmt.Sprintf("%v", bm.Status))
	builder.WriteString(", ")
	builder.WriteString("batch_no=")
	builder.WriteString(bm.BatchNo)
	builder.WriteString(", ")
	builder.WriteString("task_name=")
	builder.WriteString(bm.TaskName)
	builder.WriteString(", ")
	builder.WriteString("fromwxid=")
	builder.WriteString(bm.Fromwxid)
	builder.WriteString(", ")
	builder.WriteString("msg=")
	builder.WriteString(bm.Msg)
	builder.WriteString(", ")
	builder.WriteString("tag=")
	builder.WriteString(bm.Tag)
	builder.WriteString(", ")
	builder.WriteString("tagids=")
	builder.WriteString(bm.Tagids)
	builder.WriteString(", ")
	builder.WriteString("total=")
	builder.WriteString(fmt.Sprintf("%v", bm.Total))
	builder.WriteString(", ")
	builder.WriteString("success=")
	builder.WriteString(fmt.Sprintf("%v", bm.Success))
	builder.WriteString(", ")
	builder.WriteString("fail=")
	builder.WriteString(fmt.Sprintf("%v", bm.Fail))
	builder.WriteString(", ")
	builder.WriteString("start_time=")
	builder.WriteString(bm.StartTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("stop_time=")
	builder.WriteString(bm.StopTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("send_time=")
	builder.WriteString(bm.SendTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("type=")
	builder.WriteString(fmt.Sprintf("%v", bm.Type))
	builder.WriteString(", ")
	builder.WriteString("organization_id=")
	builder.WriteString(fmt.Sprintf("%v", bm.OrganizationID))
	builder.WriteString(", ")
	builder.WriteString("ctype=")
	builder.WriteString(fmt.Sprintf("%v", bm.Ctype))
	builder.WriteString(", ")
	builder.WriteString("cc=")
	builder.WriteString(bm.Cc)
	builder.WriteString(", ")
	builder.WriteString("phone=")
	builder.WriteString(bm.Phone)
	builder.WriteString(", ")
	builder.WriteString("template_name=")
	builder.WriteString(bm.TemplateName)
	builder.WriteString(", ")
	builder.WriteString("template_code=")
	builder.WriteString(bm.TemplateCode)
	builder.WriteString(", ")
	builder.WriteString("lang=")
	builder.WriteString(bm.Lang)
	builder.WriteByte(')')
	return builder.String()
}

// BatchMsgs is a parsable slice of BatchMsg.
type BatchMsgs []*BatchMsg