// 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/paymentproviderinstance"
)

// PaymentProviderInstance is the model entity for the PaymentProviderInstance schema.
type PaymentProviderInstance struct {
	config `json:"-"`
	// ID of the ent.
	ID int64 `json:"id,omitempty"`
	// ProviderKey holds the value of the "provider_key" field.
	ProviderKey string `json:"provider_key,omitempty"`
	// Name holds the value of the "name" field.
	Name string `json:"name,omitempty"`
	// Config holds the value of the "config" field.
	Config string `json:"config,omitempty"`
	// SupportedTypes holds the value of the "supported_types" field.
	SupportedTypes string `json:"supported_types,omitempty"`
	// Enabled holds the value of the "enabled" field.
	Enabled bool `json:"enabled,omitempty"`
	// PaymentMode holds the value of the "payment_mode" field.
	PaymentMode string `json:"payment_mode,omitempty"`
	// SortOrder holds the value of the "sort_order" field.
	SortOrder int `json:"sort_order,omitempty"`
	// Limits holds the value of the "limits" field.
	Limits string `json:"limits,omitempty"`
	// RefundEnabled holds the value of the "refund_enabled" field.
	RefundEnabled bool `json:"refund_enabled,omitempty"`
	// AllowUserRefund holds the value of the "allow_user_refund" field.
	AllowUserRefund bool `json:"allow_user_refund,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 (*PaymentProviderInstance) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case paymentproviderinstance.FieldEnabled, paymentproviderinstance.FieldRefundEnabled, paymentproviderinstance.FieldAllowUserRefund:
			values[i] = new(sql.NullBool)
		case paymentproviderinstance.FieldID, paymentproviderinstance.FieldSortOrder:
			values[i] = new(sql.NullInt64)
		case paymentproviderinstance.FieldProviderKey, paymentproviderinstance.FieldName, paymentproviderinstance.FieldConfig, paymentproviderinstance.FieldSupportedTypes, paymentproviderinstance.FieldPaymentMode, paymentproviderinstance.FieldLimits:
			values[i] = new(sql.NullString)
		case paymentproviderinstance.FieldCreatedAt, paymentproviderinstance.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 PaymentProviderInstance fields.
func (_m *PaymentProviderInstance) 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 paymentproviderinstance.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 paymentproviderinstance.FieldProviderKey:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field provider_key", values[i])
			} else if value.Valid {
				_m.ProviderKey = value.String
			}
		case paymentproviderinstance.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 paymentproviderinstance.FieldConfig:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field config", values[i])
			} else if value.Valid {
				_m.Config = value.String
			}
		case paymentproviderinstance.FieldSupportedTypes:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field supported_types", values[i])
			} else if value.Valid {
				_m.SupportedTypes = value.String
			}
		case paymentproviderinstance.FieldEnabled:
			if value, ok := values[i].(*sql.NullBool); !ok {
				return fmt.Errorf("unexpected type %T for field enabled", values[i])
			} else if value.Valid {
				_m.Enabled = value.Bool
			}
		case paymentproviderinstance.FieldPaymentMode:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field payment_mode", values[i])
			} else if value.Valid {
				_m.PaymentMode = value.String
			}
		case paymentproviderinstance.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 paymentproviderinstance.FieldLimits:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field limits", values[i])
			} else if value.Valid {
				_m.Limits = value.String
			}
		case paymentproviderinstance.FieldRefundEnabled:
			if value, ok := values[i].(*sql.NullBool); !ok {
				return fmt.Errorf("unexpected type %T for field refund_enabled", values[i])
			} else if value.Valid {
				_m.RefundEnabled = value.Bool
			}
		case paymentproviderinstance.FieldAllowUserRefund:
			if value, ok := values[i].(*sql.NullBool); !ok {
				return fmt.Errorf("unexpected type %T for field allow_user_refund", values[i])
			} else if value.Valid {
				_m.AllowUserRefund = value.Bool
			}
		case paymentproviderinstance.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 paymentproviderinstance.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 PaymentProviderInstance.
// This includes values selected through modifiers, order, etc.
func (_m *PaymentProviderInstance) Value(name string) (ent.Value, error) {
	return _m.selectValues.Get(name)
}

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

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

// String implements the fmt.Stringer.
func (_m *PaymentProviderInstance) String() string {
	var builder strings.Builder
	builder.WriteString("PaymentProviderInstance(")
	builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
	builder.WriteString("provider_key=")
	builder.WriteString(_m.ProviderKey)
	builder.WriteString(", ")
	builder.WriteString("name=")
	builder.WriteString(_m.Name)
	builder.WriteString(", ")
	builder.WriteString("config=")
	builder.WriteString(_m.Config)
	builder.WriteString(", ")
	builder.WriteString("supported_types=")
	builder.WriteString(_m.SupportedTypes)
	builder.WriteString(", ")
	builder.WriteString("enabled=")
	builder.WriteString(fmt.Sprintf("%v", _m.Enabled))
	builder.WriteString(", ")
	builder.WriteString("payment_mode=")
	builder.WriteString(_m.PaymentMode)
	builder.WriteString(", ")
	builder.WriteString("sort_order=")
	builder.WriteString(fmt.Sprintf("%v", _m.SortOrder))
	builder.WriteString(", ")
	builder.WriteString("limits=")
	builder.WriteString(_m.Limits)
	builder.WriteString(", ")
	builder.WriteString("refund_enabled=")
	builder.WriteString(fmt.Sprintf("%v", _m.RefundEnabled))
	builder.WriteString(", ")
	builder.WriteString("allow_user_refund=")
	builder.WriteString(fmt.Sprintf("%v", _m.AllowUserRefund))
	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()
}

// PaymentProviderInstances is a parsable slice of PaymentProviderInstance.
type PaymentProviderInstances []*PaymentProviderInstance
