// Code generated by ent, DO NOT EDIT.

package ent

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

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

// WhatsappChannel is the model entity for the WhatsappChannel schema.
type WhatsappChannel 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"`
	// ak
	Ak string `json:"ak,omitempty"`
	// 端口号
	Sk string `json:"sk,omitempty"`
	// 通道ID
	WaID string `json:"wa_id,omitempty"`
	// 通道名
	WaName string `json:"wa_name,omitempty"`
	// WABA ID
	WabaID uint64 `json:"waba_id,omitempty"`
	// 商业平台ID
	BusinessID uint64 `json:"business_id,omitempty"`
	// 机构 ID
	OrganizationID uint64 `json:"organization_id,omitempty"`
	// 认证主体
	VerifyAccount string `json:"verify_account,omitempty"`
	selectValues  sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*WhatsappChannel) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case whatsappchannel.FieldID, whatsappchannel.FieldStatus, whatsappchannel.FieldWabaID, whatsappchannel.FieldBusinessID, whatsappchannel.FieldOrganizationID:
			values[i] = new(sql.NullInt64)
		case whatsappchannel.FieldAk, whatsappchannel.FieldSk, whatsappchannel.FieldWaID, whatsappchannel.FieldWaName, whatsappchannel.FieldVerifyAccount:
			values[i] = new(sql.NullString)
		case whatsappchannel.FieldCreatedAt, whatsappchannel.FieldUpdatedAt, whatsappchannel.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 WhatsappChannel fields.
func (wc *WhatsappChannel) 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 whatsappchannel.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			wc.ID = uint64(value.Int64)
		case whatsappchannel.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 {
				wc.CreatedAt = value.Time
			}
		case whatsappchannel.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 {
				wc.UpdatedAt = value.Time
			}
		case whatsappchannel.FieldStatus:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				wc.Status = uint8(value.Int64)
			}
		case whatsappchannel.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 {
				wc.DeletedAt = value.Time
			}
		case whatsappchannel.FieldAk:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field ak", values[i])
			} else if value.Valid {
				wc.Ak = value.String
			}
		case whatsappchannel.FieldSk:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field sk", values[i])
			} else if value.Valid {
				wc.Sk = value.String
			}
		case whatsappchannel.FieldWaID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field wa_id", values[i])
			} else if value.Valid {
				wc.WaID = value.String
			}
		case whatsappchannel.FieldWaName:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field wa_name", values[i])
			} else if value.Valid {
				wc.WaName = value.String
			}
		case whatsappchannel.FieldWabaID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field waba_id", values[i])
			} else if value.Valid {
				wc.WabaID = uint64(value.Int64)
			}
		case whatsappchannel.FieldBusinessID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field business_id", values[i])
			} else if value.Valid {
				wc.BusinessID = uint64(value.Int64)
			}
		case whatsappchannel.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 {
				wc.OrganizationID = uint64(value.Int64)
			}
		case whatsappchannel.FieldVerifyAccount:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field verify_account", values[i])
			} else if value.Valid {
				wc.VerifyAccount = value.String
			}
		default:
			wc.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (wc *WhatsappChannel) String() string {
	var builder strings.Builder
	builder.WriteString("WhatsappChannel(")
	builder.WriteString(fmt.Sprintf("id=%v, ", wc.ID))
	builder.WriteString("created_at=")
	builder.WriteString(wc.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(wc.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(fmt.Sprintf("%v", wc.Status))
	builder.WriteString(", ")
	builder.WriteString("deleted_at=")
	builder.WriteString(wc.DeletedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("ak=")
	builder.WriteString(wc.Ak)
	builder.WriteString(", ")
	builder.WriteString("sk=")
	builder.WriteString(wc.Sk)
	builder.WriteString(", ")
	builder.WriteString("wa_id=")
	builder.WriteString(wc.WaID)
	builder.WriteString(", ")
	builder.WriteString("wa_name=")
	builder.WriteString(wc.WaName)
	builder.WriteString(", ")
	builder.WriteString("waba_id=")
	builder.WriteString(fmt.Sprintf("%v", wc.WabaID))
	builder.WriteString(", ")
	builder.WriteString("business_id=")
	builder.WriteString(fmt.Sprintf("%v", wc.BusinessID))
	builder.WriteString(", ")
	builder.WriteString("organization_id=")
	builder.WriteString(fmt.Sprintf("%v", wc.OrganizationID))
	builder.WriteString(", ")
	builder.WriteString("verify_account=")
	builder.WriteString(wc.VerifyAccount)
	builder.WriteByte(')')
	return builder.String()
}

// WhatsappChannels is a parsable slice of WhatsappChannel.
type WhatsappChannels []*WhatsappChannel
