// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
	"github.com/Wei-Shaw/sub2api/ent/subscriptionplan"
)

// SubscriptionPlan is the model entity for the SubscriptionPlan schema.
type SubscriptionPlan 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"`
	// Name holds the value of the "name" field.
	Name string `json:"name,omitempty"`
	// Description holds the value of the "description" field.
	Description string `json:"description,omitempty"`
	// Price holds the value of the "price" field.
	Price float64 `json:"price,omitempty"`
	// OriginalPrice holds the value of the "original_price" field.
	OriginalPrice *float64 `json:"original_price,omitempty"`
	// ValidityDays holds the value of the "validity_days" field.
	ValidityDays int `json:"validity_days,omitempty"`
	// ValidityUnit holds the value of the "validity_unit" field.
	ValidityUnit string `json:"validity_unit,omitempty"`
	// Features holds the value of the "features" field.
	Features string `json:"features,omitempty"`
	// ProductName holds the value of the "product_name" field.
	ProductName string `json:"product_name,omitempty"`
	// ForSale holds the value of the "for_sale" field.
	ForSale bool `json:"for_sale,omitempty"`
	// SortOrder holds the value of the "sort_order" field.
	SortOrder int `json:"sort_order,omitempty"`
	// CreatedAt holds the value of the "created_at" field.
	CreatedAt time.Time `json:"created_at,omitempty"`
	// UpdatedAt holds the value of the "updated_at" field.
	UpdatedAt    time.Time `json:"updated_at,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*SubscriptionPlan) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case subscriptionplan.FieldForSale:
			values[i] = new(sql.NullBool)
		case subscriptionplan.FieldPrice, subscriptionplan.FieldOriginalPrice:
			values[i] = new(sql.NullFloat64)
		case subscriptionplan.FieldID, subscriptionplan.FieldGroupID, subscriptionplan.FieldValidityDays, subscriptionplan.FieldSortOrder:
			values[i] = new(sql.NullInt64)
		case subscriptionplan.FieldName, subscriptionplan.FieldDescription, subscriptionplan.FieldValidityUnit, subscriptionplan.FieldFeatures, subscriptionplan.FieldProductName:
			values[i] = new(sql.NullString)
		case subscriptionplan.FieldCreatedAt, subscriptionplan.FieldUpdatedAt:
			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 SubscriptionPlan fields.
func (_m *SubscriptionPlan) 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 subscriptionplan.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			_m.ID = int64(value.Int64)
		case subscriptionplan.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 {
				_m.GroupID = value.Int64
			}
		case subscriptionplan.FieldName:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field name", values[i])
			} else if value.Valid {
				_m.Name = value.String
			}
		case subscriptionplan.FieldDescription:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field description", values[i])
			} else if value.Valid {
				_m.Description = value.String
			}
		case subscriptionplan.FieldPrice:
			if value, ok := values[i].(*sql.NullFloat64); !ok {
				return fmt.Errorf("unexpected type %T for field price", values[i])
			} else if value.Valid {
				_m.Price = value.Float64
			}
		case subscriptionplan.FieldOriginalPrice:
			if value, ok := values[i].(*sql.NullFloat64); !ok {
				return fmt.Errorf("unexpected type %T for field original_price", values[i])
			} else if value.Valid {
				_m.OriginalPrice = new(float64)
				*_m.OriginalPrice = value.Float64
			}
		case subscriptionplan.FieldValidityDays:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field validity_days", values[i])
			} else if value.Valid {
				_m.ValidityDays = int(value.Int64)
			}
		case subscriptionplan.FieldValidityUnit:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field validity_unit", values[i])
			} else if value.Valid {
				_m.ValidityUnit = value.String
			}
		case subscriptionplan.FieldFeatures:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field features", values[i])
			} else if value.Valid {
				_m.Features = value.String
			}
		case subscriptionplan.FieldProductName:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field product_name", values[i])
			} else if value.Valid {
				_m.ProductName = value.String
			}
		case subscriptionplan.FieldForSale:
			if value, ok := values[i].(*sql.NullBool); !ok {
				return fmt.Errorf("unexpected type %T for field for_sale", values[i])
			} else if value.Valid {
				_m.ForSale = value.Bool
			}
		case subscriptionplan.FieldSortOrder:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field sort_order", values[i])
			} else if value.Valid {
				_m.SortOrder = int(value.Int64)
			}
		case subscriptionplan.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 {
				_m.CreatedAt = value.Time
			}
		case subscriptionplan.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 {
				_m.UpdatedAt = value.Time
			}
		default:
			_m.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (_m *SubscriptionPlan) String() string {
	var builder strings.Builder
	builder.WriteString("SubscriptionPlan(")
	builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
	builder.WriteString("group_id=")
	builder.WriteString(fmt.Sprintf("%v", _m.GroupID))
	builder.WriteString(", ")
	builder.WriteString("name=")
	builder.WriteString(_m.Name)
	builder.WriteString(", ")
	builder.WriteString("description=")
	builder.WriteString(_m.Description)
	builder.WriteString(", ")
	builder.WriteString("price=")
	builder.WriteString(fmt.Sprintf("%v", _m.Price))
	builder.WriteString(", ")
	if v := _m.OriginalPrice; v != nil {
		builder.WriteString("original_price=")
		builder.WriteString(fmt.Sprintf("%v", *v))
	}
	builder.WriteString(", ")
	builder.WriteString("validity_days=")
	builder.WriteString(fmt.Sprintf("%v", _m.ValidityDays))
	builder.WriteString(", ")
	builder.WriteString("validity_unit=")
	builder.WriteString(_m.ValidityUnit)
	builder.WriteString(", ")
	builder.WriteString("features=")
	builder.WriteString(_m.Features)
	builder.WriteString(", ")
	builder.WriteString("product_name=")
	builder.WriteString(_m.ProductName)
	builder.WriteString(", ")
	builder.WriteString("for_sale=")
	builder.WriteString(fmt.Sprintf("%v", _m.ForSale))
	builder.WriteString(", ")
	builder.WriteString("sort_order=")
	builder.WriteString(fmt.Sprintf("%v", _m.SortOrder))
	builder.WriteString(", ")
	builder.WriteString("created_at=")
	builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
	builder.WriteByte(')')
	return builder.String()
}

// SubscriptionPlans is a parsable slice of SubscriptionPlan.
type SubscriptionPlans []*SubscriptionPlan
