// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
	"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/oauthprovider"
)

// OAuth提供商
type OauthProvider struct {
	config `json:"-"`
	// ID of the ent.
	// Primary Key | 主键
	ID int64 `json:"id,omitempty"`
	// Create Time | 创建时间
	CreatedAt time.Time `json:"created_at,omitempty"`
	// Update Time | 更新时间
	UpdatedAt time.Time `json:"updated_at,omitempty"`
	// Soft delete | 软删除（逻辑删除）
	DeletedAt time.Time `json:"deleted_at,omitempty"`
	// The provider's name | 提供商名称
	Name string `json:"name,omitempty"`
	// The client id | 客户端 id
	ClientID string `json:"client_id,omitempty"`
	// The client secret | 客户端密钥
	ClientSecret string `json:"client_secret,omitempty"`
	// The redirect url | 跳转地址
	RedirectURL string `json:"redirect_url,omitempty"`
	// The scopes | 权限范围
	Scopes string `json:"scopes,omitempty"`
	// The auth url of the provider | 认证地址
	AuthURL string `json:"auth_url,omitempty"`
	// The token url of the provider | 获取 Token 地址
	TokenURL string `json:"token_url,omitempty"`
	// The URL to request user information by token | 用户信息请求地址
	InfoURL string `json:"info_url,omitempty"`
	// The description of the provider | 提供商描述
	Description string `json:"description,omitempty"`
	// The system internal oauth provider | 系统内置提供商
	System bool `json:"system,omitempty"`
	// The oauth provider init status | 提供商初始化状态
	Init         bool `json:"init,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*OauthProvider) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case oauthprovider.FieldSystem, oauthprovider.FieldInit:
			values[i] = new(sql.NullBool)
		case oauthprovider.FieldID:
			values[i] = new(sql.NullInt64)
		case oauthprovider.FieldName, oauthprovider.FieldClientID, oauthprovider.FieldClientSecret, oauthprovider.FieldRedirectURL, oauthprovider.FieldScopes, oauthprovider.FieldAuthURL, oauthprovider.FieldTokenURL, oauthprovider.FieldInfoURL, oauthprovider.FieldDescription:
			values[i] = new(sql.NullString)
		case oauthprovider.FieldCreatedAt, oauthprovider.FieldUpdatedAt, oauthprovider.FieldDeletedAt:
			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 OauthProvider fields.
func (op *OauthProvider) 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 oauthprovider.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			op.ID = int64(value.Int64)
		case oauthprovider.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 {
				op.CreatedAt = value.Time
			}
		case oauthprovider.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 {
				op.UpdatedAt = value.Time
			}
		case oauthprovider.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 {
				op.DeletedAt = value.Time
			}
		case oauthprovider.FieldName:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field name", values[i])
			} else if value.Valid {
				op.Name = value.String
			}
		case oauthprovider.FieldClientID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field client_id", values[i])
			} else if value.Valid {
				op.ClientID = value.String
			}
		case oauthprovider.FieldClientSecret:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field client_secret", values[i])
			} else if value.Valid {
				op.ClientSecret = value.String
			}
		case oauthprovider.FieldRedirectURL:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field redirect_url", values[i])
			} else if value.Valid {
				op.RedirectURL = value.String
			}
		case oauthprovider.FieldScopes:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field scopes", values[i])
			} else if value.Valid {
				op.Scopes = value.String
			}
		case oauthprovider.FieldAuthURL:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field auth_url", values[i])
			} else if value.Valid {
				op.AuthURL = value.String
			}
		case oauthprovider.FieldTokenURL:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field token_url", values[i])
			} else if value.Valid {
				op.TokenURL = value.String
			}
		case oauthprovider.FieldInfoURL:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field info_url", values[i])
			} else if value.Valid {
				op.InfoURL = value.String
			}
		case oauthprovider.FieldDescription:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field description", values[i])
			} else if value.Valid {
				op.Description = value.String
			}
		case oauthprovider.FieldSystem:
			if value, ok := values[i].(*sql.NullBool); !ok {
				return fmt.Errorf("unexpected type %T for field system", values[i])
			} else if value.Valid {
				op.System = value.Bool
			}
		case oauthprovider.FieldInit:
			if value, ok := values[i].(*sql.NullBool); !ok {
				return fmt.Errorf("unexpected type %T for field init", values[i])
			} else if value.Valid {
				op.Init = value.Bool
			}
		default:
			op.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (op *OauthProvider) String() string {
	var builder strings.Builder
	builder.WriteString("OauthProvider(")
	builder.WriteString(fmt.Sprintf("id=%v, ", op.ID))
	builder.WriteString("created_at=")
	builder.WriteString(op.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(op.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("deleted_at=")
	builder.WriteString(op.DeletedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("name=")
	builder.WriteString(op.Name)
	builder.WriteString(", ")
	builder.WriteString("client_id=")
	builder.WriteString(op.ClientID)
	builder.WriteString(", ")
	builder.WriteString("client_secret=")
	builder.WriteString(op.ClientSecret)
	builder.WriteString(", ")
	builder.WriteString("redirect_url=")
	builder.WriteString(op.RedirectURL)
	builder.WriteString(", ")
	builder.WriteString("scopes=")
	builder.WriteString(op.Scopes)
	builder.WriteString(", ")
	builder.WriteString("auth_url=")
	builder.WriteString(op.AuthURL)
	builder.WriteString(", ")
	builder.WriteString("token_url=")
	builder.WriteString(op.TokenURL)
	builder.WriteString(", ")
	builder.WriteString("info_url=")
	builder.WriteString(op.InfoURL)
	builder.WriteString(", ")
	builder.WriteString("description=")
	builder.WriteString(op.Description)
	builder.WriteString(", ")
	builder.WriteString("system=")
	builder.WriteString(fmt.Sprintf("%v", op.System))
	builder.WriteString(", ")
	builder.WriteString("init=")
	builder.WriteString(fmt.Sprintf("%v", op.Init))
	builder.WriteByte(')')
	return builder.String()
}

// OauthProviders is a parsable slice of OauthProvider.
type OauthProviders []*OauthProvider
