// Code generated by entc, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"

	"github.com/facebook/ent/dialect/sql"
	"github.com/kallydev/privacy/ent/sfmodel"
)

// SFModel is the model entity for the SFModel schema.
type SFModel struct {
	config `json:"-"`
	// ID of the ent.
	ID int `json:"id,omitempty"`
	// Name holds the value of the "name" field.
	Name string `json:"name,omitempty"`
	// PhoneNumber holds the value of the "phone_number" field.
	PhoneNumber int64 `json:"phone_number,omitempty"`
	// Address holds the value of the "address" field.
	Address string `json:"address,omitempty"`
}

// scanValues returns the types for scanning values from sql.Rows.
func (*SFModel) scanValues() []interface{} {
	return []interface{}{
		&sql.NullInt64{},  // id
		&sql.NullString{}, // name
		&sql.NullInt64{},  // phone_number
		&sql.NullString{}, // address
	}
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the SFModel fields.
func (sm *SFModel) assignValues(values ...interface{}) error {
	if m, n := len(values), len(sfmodel.Columns); m < n {
		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
	}
	value, ok := values[0].(*sql.NullInt64)
	if !ok {
		return fmt.Errorf("unexpected type %T for field id", value)
	}
	sm.ID = int(value.Int64)
	values = values[1:]
	if value, ok := values[0].(*sql.NullString); !ok {
		return fmt.Errorf("unexpected type %T for field name", values[0])
	} else if value.Valid {
		sm.Name = value.String
	}
	if value, ok := values[1].(*sql.NullInt64); !ok {
		return fmt.Errorf("unexpected type %T for field phone_number", values[1])
	} else if value.Valid {
		sm.PhoneNumber = value.Int64
	}
	if value, ok := values[2].(*sql.NullString); !ok {
		return fmt.Errorf("unexpected type %T for field address", values[2])
	} else if value.Valid {
		sm.Address = value.String
	}
	return nil
}

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

// Unwrap unwraps the entity that was returned from a transaction after it was closed,
// so that all next queries will be executed through the driver which created the transaction.
func (sm *SFModel) Unwrap() *SFModel {
	tx, ok := sm.config.driver.(*txDriver)
	if !ok {
		panic("ent: SFModel is not a transactional entity")
	}
	sm.config.driver = tx.drv
	return sm
}

// String implements the fmt.Stringer.
func (sm *SFModel) String() string {
	var builder strings.Builder
	builder.WriteString("SFModel(")
	builder.WriteString(fmt.Sprintf("id=%v", sm.ID))
	builder.WriteString(", name=")
	builder.WriteString(sm.Name)
	builder.WriteString(", phone_number=")
	builder.WriteString(fmt.Sprintf("%v", sm.PhoneNumber))
	builder.WriteString(", address=")
	builder.WriteString(sm.Address)
	builder.WriteByte(')')
	return builder.String()
}

// SFModels is a parsable slice of SFModel.
type SFModels []*SFModel

func (sm SFModels) config(cfg config) {
	for _i := range sm {
		sm[_i].config = cfg
	}
}