// Code generated by ent, DO NOT EDIT.

package ent

import (
	"PasswordManager/ent/password"
	"PasswordManager/ent/vault"
	"fmt"
	"strings"

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

// Password is the model entity for the Password schema.
type Password struct {
	config `json:"-"`
	// ID of the ent.
	ID uuid.UUID `form:"id" json:"id" xml:"id"`
	// 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"`
	// Username holds the value of the "username" field.
	Username []byte `json:"username,omitempty"`
	// UsernameIv holds the value of the "usernameIv" field.
	UsernameIv []byte `json:"usernameIv,omitempty"`
	// Password holds the value of the "password" field.
	Password []byte `json:"password,omitempty"`
	// PasswordIv holds the value of the "passwordIv" field.
	PasswordIv []byte `json:"passwordIv,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 PasswordQuery when eager-loading is set.
	Edges           PasswordEdges `json:"edges"`
	vault_passwords *uuid.UUID
}

// PasswordEdges holds the relations/edges for other nodes in the graph.
type PasswordEdges struct {
	// AdditionalFields holds the value of the additionalFields edge.
	AdditionalFields []*AdditionalField `json:"additionalFields,omitempty"`
	// Urls holds the value of the urls edge.
	Urls []*Url `json:"urls,omitempty"`
	// Vault holds the value of the vault edge.
	Vault *Vault `json:"vault,omitempty"`
	// loadedTypes holds the information for reporting if a
	// type was loaded (or requested) in eager-loading or not.
	loadedTypes [3]bool
}

// AdditionalFieldsOrErr returns the AdditionalFields value or an error if the edge
// was not loaded in eager-loading.
func (e PasswordEdges) AdditionalFieldsOrErr() ([]*AdditionalField, error) {
	if e.loadedTypes[0] {
		return e.AdditionalFields, nil
	}
	return nil, &NotLoadedError{edge: "additionalFields"}
}

// UrlsOrErr returns the Urls value or an error if the edge
// was not loaded in eager-loading.
func (e PasswordEdges) UrlsOrErr() ([]*Url, error) {
	if e.loadedTypes[1] {
		return e.Urls, nil
	}
	return nil, &NotLoadedError{edge: "urls"}
}

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

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

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Password fields.
func (pa *Password) 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 password.FieldID:
			if value, ok := values[i].(*uuid.UUID); !ok {
				return fmt.Errorf("unexpected type %T for field id", values[i])
			} else if value != nil {
				pa.ID = *value
			}
		case password.FieldName:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field name", values[i])
			} else if value != nil {
				pa.Name = *value
			}
		case password.FieldNameIv:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field nameIv", values[i])
			} else if value != nil {
				pa.NameIv = *value
			}
		case password.FieldUsername:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field username", values[i])
			} else if value != nil {
				pa.Username = *value
			}
		case password.FieldUsernameIv:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field usernameIv", values[i])
			} else if value != nil {
				pa.UsernameIv = *value
			}
		case password.FieldPassword:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field password", values[i])
			} else if value != nil {
				pa.Password = *value
			}
		case password.FieldPasswordIv:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field passwordIv", values[i])
			} else if value != nil {
				pa.PasswordIv = *value
			}
		case password.FieldColour:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field colour", values[i])
			} else if value != nil {
				pa.Colour = *value
			}
		case password.FieldColourIv:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field colourIv", values[i])
			} else if value != nil {
				pa.ColourIv = *value
			}
		case password.ForeignKeys[0]:
			if value, ok := values[i].(*sql.NullScanner); !ok {
				return fmt.Errorf("unexpected type %T for field vault_passwords", values[i])
			} else if value.Valid {
				pa.vault_passwords = new(uuid.UUID)
				*pa.vault_passwords = *value.S.(*uuid.UUID)
			}
		}
	}
	return nil
}

// QueryAdditionalFields queries the "additionalFields" edge of the Password entity.
func (pa *Password) QueryAdditionalFields() *AdditionalFieldQuery {
	return NewPasswordClient(pa.config).QueryAdditionalFields(pa)
}

// QueryUrls queries the "urls" edge of the Password entity.
func (pa *Password) QueryUrls() *URLQuery {
	return NewPasswordClient(pa.config).QueryUrls(pa)
}

// QueryVault queries the "vault" edge of the Password entity.
func (pa *Password) QueryVault() *VaultQuery {
	return NewPasswordClient(pa.config).QueryVault(pa)
}

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

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

// String implements the fmt.Stringer.
func (pa *Password) String() string {
	var builder strings.Builder
	builder.WriteString("Password(")
	builder.WriteString(fmt.Sprintf("id=%v, ", pa.ID))
	builder.WriteString("name=")
	builder.WriteString(fmt.Sprintf("%v", pa.Name))
	builder.WriteString(", ")
	builder.WriteString("nameIv=")
	builder.WriteString(fmt.Sprintf("%v", pa.NameIv))
	builder.WriteString(", ")
	builder.WriteString("username=")
	builder.WriteString(fmt.Sprintf("%v", pa.Username))
	builder.WriteString(", ")
	builder.WriteString("usernameIv=")
	builder.WriteString(fmt.Sprintf("%v", pa.UsernameIv))
	builder.WriteString(", ")
	builder.WriteString("password=")
	builder.WriteString(fmt.Sprintf("%v", pa.Password))
	builder.WriteString(", ")
	builder.WriteString("passwordIv=")
	builder.WriteString(fmt.Sprintf("%v", pa.PasswordIv))
	builder.WriteString(", ")
	builder.WriteString("colour=")
	builder.WriteString(fmt.Sprintf("%v", pa.Colour))
	builder.WriteString(", ")
	builder.WriteString("colourIv=")
	builder.WriteString(fmt.Sprintf("%v", pa.ColourIv))
	builder.WriteByte(')')
	return builder.String()
}

// Passwords is a parsable slice of Password.
type Passwords []*Password
