// Code generated by ent, DO NOT EDIT.

package ent

import (
	"encoding/json"
	"fmt"
	"strings"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
	"github.com/AvengeMedia/dankcalendar/core/ent/account"
)

// Account is the model entity for the Account schema.
type Account struct {
	config `json:"-"`
	// ID of the ent.
	ID string `json:"id,omitempty"`
	// Kind holds the value of the "kind" field.
	Kind account.Kind `json:"kind,omitempty"`
	// DisplayName holds the value of the "display_name" field.
	DisplayName string `json:"display_name,omitempty"`
	// Settings holds the value of the "settings" field.
	Settings map[string]interface{} `json:"settings,omitempty"`
	// NeedsReauth holds the value of the "needs_reauth" field.
	NeedsReauth bool `json:"needs_reauth,omitempty"`
	// AuthError holds the value of the "auth_error" field.
	AuthError string `json:"auth_error,omitempty"`
	// SyncNotice holds the value of the "sync_notice" field.
	SyncNotice string `json:"sync_notice,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"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the AccountQuery when eager-loading is set.
	Edges        AccountEdges `json:"edges"`
	selectValues sql.SelectValues
}

// AccountEdges holds the relations/edges for other nodes in the graph.
type AccountEdges struct {
	// Calendars holds the value of the calendars edge.
	Calendars []*Calendar `json:"calendars,omitempty"`
	// Secrets holds the value of the secrets edge.
	Secrets []*Secret `json:"secrets,omitempty"`
	// loadedTypes holds the information for reporting if a
	// type was loaded (or requested) in eager-loading or not.
	loadedTypes [2]bool
}

// CalendarsOrErr returns the Calendars value or an error if the edge
// was not loaded in eager-loading.
func (e AccountEdges) CalendarsOrErr() ([]*Calendar, error) {
	if e.loadedTypes[0] {
		return e.Calendars, nil
	}
	return nil, &NotLoadedError{edge: "calendars"}
}

// SecretsOrErr returns the Secrets value or an error if the edge
// was not loaded in eager-loading.
func (e AccountEdges) SecretsOrErr() ([]*Secret, error) {
	if e.loadedTypes[1] {
		return e.Secrets, nil
	}
	return nil, &NotLoadedError{edge: "secrets"}
}

// scanValues returns the types for scanning values from sql.Rows.
func (*Account) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case account.FieldSettings:
			values[i] = new([]byte)
		case account.FieldNeedsReauth:
			values[i] = new(sql.NullBool)
		case account.FieldID, account.FieldKind, account.FieldDisplayName, account.FieldAuthError, account.FieldSyncNotice:
			values[i] = new(sql.NullString)
		case account.FieldCreatedAt, account.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 Account fields.
func (_m *Account) 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 account.FieldID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field id", values[i])
			} else if value.Valid {
				_m.ID = value.String
			}
		case account.FieldKind:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field kind", values[i])
			} else if value.Valid {
				_m.Kind = account.Kind(value.String)
			}
		case account.FieldDisplayName:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field display_name", values[i])
			} else if value.Valid {
				_m.DisplayName = value.String
			}
		case account.FieldSettings:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field settings", values[i])
			} else if value != nil && len(*value) > 0 {
				if err := json.Unmarshal(*value, &_m.Settings); err != nil {
					return fmt.Errorf("unmarshal field settings: %w", err)
				}
			}
		case account.FieldNeedsReauth:
			if value, ok := values[i].(*sql.NullBool); !ok {
				return fmt.Errorf("unexpected type %T for field needs_reauth", values[i])
			} else if value.Valid {
				_m.NeedsReauth = value.Bool
			}
		case account.FieldAuthError:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field auth_error", values[i])
			} else if value.Valid {
				_m.AuthError = value.String
			}
		case account.FieldSyncNotice:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field sync_notice", values[i])
			} else if value.Valid {
				_m.SyncNotice = value.String
			}
		case account.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 account.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 Account.
// This includes values selected through modifiers, order, etc.
func (_m *Account) Value(name string) (ent.Value, error) {
	return _m.selectValues.Get(name)
}

// QueryCalendars queries the "calendars" edge of the Account entity.
func (_m *Account) QueryCalendars() *CalendarQuery {
	return NewAccountClient(_m.config).QueryCalendars(_m)
}

// QuerySecrets queries the "secrets" edge of the Account entity.
func (_m *Account) QuerySecrets() *SecretQuery {
	return NewAccountClient(_m.config).QuerySecrets(_m)
}

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

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

// String implements the fmt.Stringer.
func (_m *Account) String() string {
	var builder strings.Builder
	builder.WriteString("Account(")
	builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
	builder.WriteString("kind=")
	builder.WriteString(fmt.Sprintf("%v", _m.Kind))
	builder.WriteString(", ")
	builder.WriteString("display_name=")
	builder.WriteString(_m.DisplayName)
	builder.WriteString(", ")
	builder.WriteString("settings=")
	builder.WriteString(fmt.Sprintf("%v", _m.Settings))
	builder.WriteString(", ")
	builder.WriteString("needs_reauth=")
	builder.WriteString(fmt.Sprintf("%v", _m.NeedsReauth))
	builder.WriteString(", ")
	builder.WriteString("auth_error=")
	builder.WriteString(_m.AuthError)
	builder.WriteString(", ")
	builder.WriteString("sync_notice=")
	builder.WriteString(_m.SyncNotice)
	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()
}

// Accounts is a parsable slice of Account.
type Accounts []*Account
