// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"galileo/ent/groupmember"
	"strings"
	"time"

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

// GroupMember is the model entity for the GroupMember schema.
type GroupMember struct {
	config `json:"-"`
	// ID of the ent.
	ID int64 `json:"id,omitempty"`
	// GroupID holds the value of the "group_id" field.
	GroupID int64 `json:"group_id,omitempty"`
	// UserID holds the value of the "user_id" field.
	UserID uint32 `json:"user_id,omitempty"`
	// Role holds the value of the "role" field.
	Role uint8 `json:"role,omitempty"`
	// CreatedAt holds the value of the "created_at" field.
	CreatedAt time.Time `json:"created_at,omitempty"`
	// CreatedBy holds the value of the "created_by" field.
	CreatedBy uint32 `json:"created_by,omitempty"`
	// DeletedAt holds the value of the "deleted_at" field.
	DeletedAt time.Time `json:"deleted_at,omitempty"`
	// DeletedBy holds the value of the "deleted_by" field.
	DeletedBy uint32 `json:"deleted_by,omitempty"`
}

// scanValues returns the types for scanning values from sql.Rows.
func (*GroupMember) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case groupmember.FieldID, groupmember.FieldGroupID, groupmember.FieldUserID, groupmember.FieldRole, groupmember.FieldCreatedBy, groupmember.FieldDeletedBy:
			values[i] = new(sql.NullInt64)
		case groupmember.FieldCreatedAt, groupmember.FieldDeletedAt:
			values[i] = new(sql.NullTime)
		default:
			return nil, fmt.Errorf("unexpected column %q for type GroupMember", columns[i])
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the GroupMember fields.
func (gm *GroupMember) 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 groupmember.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			gm.ID = int64(value.Int64)
		case groupmember.FieldGroupID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field group_id", values[i])
			} else if value.Valid {
				gm.GroupID = value.Int64
			}
		case groupmember.FieldUserID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field user_id", values[i])
			} else if value.Valid {
				gm.UserID = uint32(value.Int64)
			}
		case groupmember.FieldRole:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field role", values[i])
			} else if value.Valid {
				gm.Role = uint8(value.Int64)
			}
		case groupmember.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 {
				gm.CreatedAt = value.Time
			}
		case groupmember.FieldCreatedBy:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field created_by", values[i])
			} else if value.Valid {
				gm.CreatedBy = uint32(value.Int64)
			}
		case groupmember.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 {
				gm.DeletedAt = value.Time
			}
		case groupmember.FieldDeletedBy:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field deleted_by", values[i])
			} else if value.Valid {
				gm.DeletedBy = uint32(value.Int64)
			}
		}
	}
	return nil
}

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

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

// String implements the fmt.Stringer.
func (gm *GroupMember) String() string {
	var builder strings.Builder
	builder.WriteString("GroupMember(")
	builder.WriteString(fmt.Sprintf("id=%v, ", gm.ID))
	builder.WriteString("group_id=")
	builder.WriteString(fmt.Sprintf("%v", gm.GroupID))
	builder.WriteString(", ")
	builder.WriteString("user_id=")
	builder.WriteString(fmt.Sprintf("%v", gm.UserID))
	builder.WriteString(", ")
	builder.WriteString("role=")
	builder.WriteString(fmt.Sprintf("%v", gm.Role))
	builder.WriteString(", ")
	builder.WriteString("created_at=")
	builder.WriteString(gm.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("created_by=")
	builder.WriteString(fmt.Sprintf("%v", gm.CreatedBy))
	builder.WriteString(", ")
	builder.WriteString("deleted_at=")
	builder.WriteString(gm.DeletedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("deleted_by=")
	builder.WriteString(fmt.Sprintf("%v", gm.DeletedBy))
	builder.WriteByte(')')
	return builder.String()
}

// GroupMembers is a parsable slice of GroupMember.
type GroupMembers []*GroupMember
