// Code generated by ent, DO NOT EDIT.

package ent

import (
	"PasswordManager/ent/user"
	"PasswordManager/ent/vault"
	"fmt"
	"strings"
	"time"

	"entgo.io/ent/dialect/sql"
	"github.com/google/uuid"
)

// Vault is the model entity for the Vault schema.
type Vault struct {
	config `json:"-"`
	// ID of the ent.
	ID uuid.UUID `json:"id,omitempty"`
	// CreatedAt holds the value of the "createdAt" field.
	CreatedAt time.Time `json:"createdAt,omitempty"`
	// Name holds the value of the "name" field.
	Name []byte `json:"name,omitempty"`
	// NameIv holds the value of the "nameIv" field.
	NameIv []byte `json:"nameIv,omitempty"`
	// Colour holds the value of the "colour" field.
	Colour []byte `json:"colour,omitempty"`
	// ColourIv holds the value of the "colourIv" field.
	ColourIv []byte `json:"colourIv,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the VaultQuery when eager-loading is set.
	Edges       VaultEdges `json:"edges"`
	user_vaults *uuid.UUID
}

// VaultEdges holds the relations/edges for other nodes in the graph.
type VaultEdges struct {
	// Passwords holds the value of the passwords edge.
	Passwords []*Password `json:"passwords,omitempty"`
	// Notes holds the value of the notes edge.
	Notes []*Note `json:"notes,omitempty"`
	// User holds the value of the user edge.
	User *User `json:"user,omitempty"`
	// loadedTypes holds the information for reporting if a
	// type was loaded (or requested) in eager-loading or not.
	loadedTypes [3]bool
}

// PasswordsOrErr returns the Passwords value or an error if the edge
// was not loaded in eager-loading.
func (e VaultEdges) PasswordsOrErr() ([]*Password, error) {
	if e.loadedTypes[0] {
		return e.Passwords, nil
	}
	return nil, &NotLoadedError{edge: "passwords"}
}

// NotesOrErr returns the Notes value or an error if the edge
// was not loaded in eager-loading.
func (e VaultEdges) NotesOrErr() ([]*Note, error) {
	if e.loadedTypes[1] {
		return e.Notes, nil
	}
	return nil, &NotLoadedError{edge: "notes"}
}

// UserOrErr returns the User value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e VaultEdges) UserOrErr() (*User, error) {
	if e.loadedTypes[2] {
		if e.User == nil {
			// Edge was loaded but was not found.
			return nil, &NotFoundError{label: user.Label}
		}
		return e.User, nil
	}
	return nil, &NotLoadedError{edge: "user"}
}

// scanValues returns the types for scanning values from sql.Rows.
func (*Vault) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case vault.FieldName, vault.FieldNameIv, vault.FieldColour, vault.FieldColourIv:
			values[i] = new([]byte)
		case vault.FieldCreatedAt:
			values[i] = new(sql.NullTime)
		case vault.FieldID:
			values[i] = new(uuid.UUID)
		case vault.ForeignKeys[0]: // user_vaults
			values[i] = &sql.NullScanner{S: new(uuid.UUID)}
		default:
			return nil, fmt.Errorf("unexpected column %q for type Vault", columns[i])
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Vault fields.
func (v *Vault) 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 vault.FieldID:
			if value, ok := values[i].(*uuid.UUID); !ok {
				return fmt.Errorf("unexpected type %T for field id", values[i])
			} else if value != nil {
				v.ID = *value
			}
		case vault.FieldCreatedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field createdAt", values[i])
			} else if value.Valid {
				v.CreatedAt = value.Time
			}
		case vault.FieldName:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field name", values[i])
			} else if value != nil {
				v.Name = *value
			}
		case vault.FieldNameIv:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field nameIv", values[i])
			} else if value != nil {
				v.NameIv = *value
			}
		case vault.FieldColour:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field colour", values[i])
			} else if value != nil {
				v.Colour = *value
			}
		case vault.FieldColourIv:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field colourIv", values[i])
			} else if value != nil {
				v.ColourIv = *value
			}
		case vault.ForeignKeys[0]:
			if value, ok := values[i].(*sql.NullScanner); !ok {
				return fmt.Errorf("unexpected type %T for field user_vaults", values[i])
			} else if value.Valid {
				v.user_vaults = new(uuid.UUID)
				*v.user_vaults = *value.S.(*uuid.UUID)
			}
		}
	}
	return nil
}

// QueryPasswords queries the "passwords" edge of the Vault entity.
func (v *Vault) QueryPasswords() *PasswordQuery {
	return NewVaultClient(v.config).QueryPasswords(v)
}

// QueryNotes queries the "notes" edge of the Vault entity.
func (v *Vault) QueryNotes() *NoteQuery {
	return NewVaultClient(v.config).QueryNotes(v)
}

// QueryUser queries the "user" edge of the Vault entity.
func (v *Vault) QueryUser() *UserQuery {
	return NewVaultClient(v.config).QueryUser(v)
}

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

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

// String implements the fmt.Stringer.
func (v *Vault) String() string {
	var builder strings.Builder
	builder.WriteString("Vault(")
	builder.WriteString(fmt.Sprintf("id=%v, ", v.ID))
	builder.WriteString("createdAt=")
	builder.WriteString(v.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("name=")
	builder.WriteString(fmt.Sprintf("%v", v.Name))
	builder.WriteString(", ")
	builder.WriteString("nameIv=")
	builder.WriteString(fmt.Sprintf("%v", v.NameIv))
	builder.WriteString(", ")
	builder.WriteString("colour=")
	builder.WriteString(fmt.Sprintf("%v", v.Colour))
	builder.WriteString(", ")
	builder.WriteString("colourIv=")
	builder.WriteString(fmt.Sprintf("%v", v.ColourIv))
	builder.WriteByte(')')
	return builder.String()
}

// Vaults is a parsable slice of Vault.
type Vaults []*Vault
