// Code generated by ent, DO NOT EDIT.

package ent

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

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

// Contact is the model entity for the Contact schema.
type Contact 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
	WxWxid string `json:"wx_wxid,omitempty"`
	// 联系人类型:1好友,2群组,3公众号,4企业微信联系人
	Type int `json:"type,omitempty"`
	// 微信id 公众号微信ID
	Wxid string `json:"wxid,omitempty"`
	// 微信账号
	Account string `json:"account,omitempty"`
	// 微信昵称 群备注名称
	Nickname string `json:"nickname,omitempty"`
	// 备注名
	Markname string `json:"markname,omitempty"`
	// 头像
	Headimg string `json:"headimg,omitempty"`
	// 性别 0未知 1男 2女
	Sex int `json:"sex,omitempty"`
	// 星标 65/67=星标 1/3=未星标
	Starrole string `json:"starrole,omitempty"`
	// 不让他看我的朋友圈 0可以看 1不让看
	Dontseeit int `json:"dontseeit,omitempty"`
	// 不看他的朋友圈 0可以看 1不看 1=开启了不看他 128/129=仅聊天
	Dontseeme int `json:"dontseeme,omitempty"`
	// 所属标签id清单,多开会用逗号隔开
	Lag string `json:"lag,omitempty"`
	// 群组id
	Gid string `json:"gid,omitempty"`
	// 群组名称
	Gname string `json:"gname,omitempty"`
	// v3数据
	V3 string `json:"v3,omitempty"`
	// 机构 ID
	OrganizationID uint64 `json:"organization_id,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the ContactQuery when eager-loading is set.
	Edges        ContactEdges `json:"edges"`
	selectValues sql.SelectValues
}

// ContactEdges holds the relations/edges for other nodes in the graph.
type ContactEdges struct {
	// ContactRelationships holds the value of the contact_relationships edge.
	ContactRelationships []*LabelRelationship `json:"contact_relationships,omitempty"`
	// ContactMessages holds the value of the contact_messages edge.
	ContactMessages []*MessageRecords `json:"contact_messages,omitempty"`
	// loadedTypes holds the information for reporting if a
	// type was loaded (or requested) in eager-loading or not.
	loadedTypes [2]bool
}

// ContactRelationshipsOrErr returns the ContactRelationships value or an error if the edge
// was not loaded in eager-loading.
func (e ContactEdges) ContactRelationshipsOrErr() ([]*LabelRelationship, error) {
	if e.loadedTypes[0] {
		return e.ContactRelationships, nil
	}
	return nil, &NotLoadedError{edge: "contact_relationships"}
}

// ContactMessagesOrErr returns the ContactMessages value or an error if the edge
// was not loaded in eager-loading.
func (e ContactEdges) ContactMessagesOrErr() ([]*MessageRecords, error) {
	if e.loadedTypes[1] {
		return e.ContactMessages, nil
	}
	return nil, &NotLoadedError{edge: "contact_messages"}
}

// scanValues returns the types for scanning values from sql.Rows.
func (*Contact) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case contact.FieldID, contact.FieldStatus, contact.FieldType, contact.FieldSex, contact.FieldDontseeit, contact.FieldDontseeme, contact.FieldOrganizationID:
			values[i] = new(sql.NullInt64)
		case contact.FieldWxWxid, contact.FieldWxid, contact.FieldAccount, contact.FieldNickname, contact.FieldMarkname, contact.FieldHeadimg, contact.FieldStarrole, contact.FieldLag, contact.FieldGid, contact.FieldGname, contact.FieldV3:
			values[i] = new(sql.NullString)
		case contact.FieldCreatedAt, contact.FieldUpdatedAt, contact.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 Contact fields.
func (c *Contact) 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 contact.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			c.ID = uint64(value.Int64)
		case contact.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 {
				c.CreatedAt = value.Time
			}
		case contact.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 {
				c.UpdatedAt = value.Time
			}
		case contact.FieldStatus:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				c.Status = uint8(value.Int64)
			}
		case contact.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 {
				c.DeletedAt = value.Time
			}
		case contact.FieldWxWxid:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field wx_wxid", values[i])
			} else if value.Valid {
				c.WxWxid = value.String
			}
		case contact.FieldType:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field type", values[i])
			} else if value.Valid {
				c.Type = int(value.Int64)
			}
		case contact.FieldWxid:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field wxid", values[i])
			} else if value.Valid {
				c.Wxid = value.String
			}
		case contact.FieldAccount:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field account", values[i])
			} else if value.Valid {
				c.Account = value.String
			}
		case contact.FieldNickname:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field nickname", values[i])
			} else if value.Valid {
				c.Nickname = value.String
			}
		case contact.FieldMarkname:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field markname", values[i])
			} else if value.Valid {
				c.Markname = value.String
			}
		case contact.FieldHeadimg:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field headimg", values[i])
			} else if value.Valid {
				c.Headimg = value.String
			}
		case contact.FieldSex:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field sex", values[i])
			} else if value.Valid {
				c.Sex = int(value.Int64)
			}
		case contact.FieldStarrole:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field starrole", values[i])
			} else if value.Valid {
				c.Starrole = value.String
			}
		case contact.FieldDontseeit:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field dontseeit", values[i])
			} else if value.Valid {
				c.Dontseeit = int(value.Int64)
			}
		case contact.FieldDontseeme:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field dontseeme", values[i])
			} else if value.Valid {
				c.Dontseeme = int(value.Int64)
			}
		case contact.FieldLag:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field lag", values[i])
			} else if value.Valid {
				c.Lag = value.String
			}
		case contact.FieldGid:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field gid", values[i])
			} else if value.Valid {
				c.Gid = value.String
			}
		case contact.FieldGname:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field gname", values[i])
			} else if value.Valid {
				c.Gname = value.String
			}
		case contact.FieldV3:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field v3", values[i])
			} else if value.Valid {
				c.V3 = value.String
			}
		case contact.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 {
				c.OrganizationID = uint64(value.Int64)
			}
		default:
			c.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

// QueryContactRelationships queries the "contact_relationships" edge of the Contact entity.
func (c *Contact) QueryContactRelationships() *LabelRelationshipQuery {
	return NewContactClient(c.config).QueryContactRelationships(c)
}

// QueryContactMessages queries the "contact_messages" edge of the Contact entity.
func (c *Contact) QueryContactMessages() *MessageRecordsQuery {
	return NewContactClient(c.config).QueryContactMessages(c)
}

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

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

// String implements the fmt.Stringer.
func (c *Contact) String() string {
	var builder strings.Builder
	builder.WriteString("Contact(")
	builder.WriteString(fmt.Sprintf("id=%v, ", c.ID))
	builder.WriteString("created_at=")
	builder.WriteString(c.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(c.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(fmt.Sprintf("%v", c.Status))
	builder.WriteString(", ")
	builder.WriteString("deleted_at=")
	builder.WriteString(c.DeletedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("wx_wxid=")
	builder.WriteString(c.WxWxid)
	builder.WriteString(", ")
	builder.WriteString("type=")
	builder.WriteString(fmt.Sprintf("%v", c.Type))
	builder.WriteString(", ")
	builder.WriteString("wxid=")
	builder.WriteString(c.Wxid)
	builder.WriteString(", ")
	builder.WriteString("account=")
	builder.WriteString(c.Account)
	builder.WriteString(", ")
	builder.WriteString("nickname=")
	builder.WriteString(c.Nickname)
	builder.WriteString(", ")
	builder.WriteString("markname=")
	builder.WriteString(c.Markname)
	builder.WriteString(", ")
	builder.WriteString("headimg=")
	builder.WriteString(c.Headimg)
	builder.WriteString(", ")
	builder.WriteString("sex=")
	builder.WriteString(fmt.Sprintf("%v", c.Sex))
	builder.WriteString(", ")
	builder.WriteString("starrole=")
	builder.WriteString(c.Starrole)
	builder.WriteString(", ")
	builder.WriteString("dontseeit=")
	builder.WriteString(fmt.Sprintf("%v", c.Dontseeit))
	builder.WriteString(", ")
	builder.WriteString("dontseeme=")
	builder.WriteString(fmt.Sprintf("%v", c.Dontseeme))
	builder.WriteString(", ")
	builder.WriteString("lag=")
	builder.WriteString(c.Lag)
	builder.WriteString(", ")
	builder.WriteString("gid=")
	builder.WriteString(c.Gid)
	builder.WriteString(", ")
	builder.WriteString("gname=")
	builder.WriteString(c.Gname)
	builder.WriteString(", ")
	builder.WriteString("v3=")
	builder.WriteString(c.V3)
	builder.WriteString(", ")
	builder.WriteString("organization_id=")
	builder.WriteString(fmt.Sprintf("%v", c.OrganizationID))
	builder.WriteByte(')')
	return builder.String()
}

// Contacts is a parsable slice of Contact.
type Contacts []*Contact