// Code generated by ent, DO NOT EDIT.

package ent

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

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

// ProjectMember is the model entity for the ProjectMember schema.
type ProjectMember struct {
	config `json:"-"`
	// ID of the ent.
	ID int `json:"id,omitempty"`
	// ProjectID holds the value of the "project_id" field.
	ProjectID int64 `json:"project_id,omitempty"`
	// UserID holds the value of the "user_id" field.
	UserID uint32 `json:"user_id,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"`
	// Status holds the value of the "status" field.
	Status int8 `json:"status,omitempty"`
	// Description holds the value of the "description" field.
	Description string `json:"description,omitempty"`
	// Remark holds the value of the "remark" field.
	Remark string `json:"remark,omitempty"`
	// Role holds the value of the "role" field.
	Role uint8 `json:"role,omitempty"`
}

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

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the ProjectMember fields.
func (pm *ProjectMember) 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 projectmember.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			pm.ID = int(value.Int64)
		case projectmember.FieldProjectID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field project_id", values[i])
			} else if value.Valid {
				pm.ProjectID = value.Int64
			}
		case projectmember.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 {
				pm.UserID = uint32(value.Int64)
			}
		case projectmember.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 {
				pm.CreatedAt = value.Time
			}
		case projectmember.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 {
				pm.CreatedBy = uint32(value.Int64)
			}
		case projectmember.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 {
				pm.DeletedAt = value.Time
			}
		case projectmember.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 {
				pm.DeletedBy = uint32(value.Int64)
			}
		case projectmember.FieldStatus:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				pm.Status = int8(value.Int64)
			}
		case projectmember.FieldDescription:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field description", values[i])
			} else if value.Valid {
				pm.Description = value.String
			}
		case projectmember.FieldRemark:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field remark", values[i])
			} else if value.Valid {
				pm.Remark = value.String
			}
		case projectmember.FieldRole:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field role", values[i])
			} else if value.Valid {
				pm.Role = uint8(value.Int64)
			}
		}
	}
	return nil
}

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

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

// String implements the fmt.Stringer.
func (pm *ProjectMember) String() string {
	var builder strings.Builder
	builder.WriteString("ProjectMember(")
	builder.WriteString(fmt.Sprintf("id=%v, ", pm.ID))
	builder.WriteString("project_id=")
	builder.WriteString(fmt.Sprintf("%v", pm.ProjectID))
	builder.WriteString(", ")
	builder.WriteString("user_id=")
	builder.WriteString(fmt.Sprintf("%v", pm.UserID))
	builder.WriteString(", ")
	builder.WriteString("created_at=")
	builder.WriteString(pm.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("created_by=")
	builder.WriteString(fmt.Sprintf("%v", pm.CreatedBy))
	builder.WriteString(", ")
	builder.WriteString("deleted_at=")
	builder.WriteString(pm.DeletedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("deleted_by=")
	builder.WriteString(fmt.Sprintf("%v", pm.DeletedBy))
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(fmt.Sprintf("%v", pm.Status))
	builder.WriteString(", ")
	builder.WriteString("description=")
	builder.WriteString(pm.Description)
	builder.WriteString(", ")
	builder.WriteString("remark=")
	builder.WriteString(pm.Remark)
	builder.WriteString(", ")
	builder.WriteString("role=")
	builder.WriteString(fmt.Sprintf("%v", pm.Role))
	builder.WriteByte(')')
	return builder.String()
}

// ProjectMembers is a parsable slice of ProjectMember.
type ProjectMembers []*ProjectMember
