// Code generated by ent, DO NOT EDIT.

package ent

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

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

// Note is the model entity for the Note schema.
type Note struct {
	config `json:"-"`
	// ID of the ent.
	ID uuid.UUID `json:"id,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"`
	// Title holds the value of the "title" field.
	Title []byte `json:"title,omitempty"`
	// TitleIv holds the value of the "titleIv" field.
	TitleIv []byte `json:"titleIv,omitempty"`
	// Content holds the value of the "content" field.
	Content []byte `json:"content,omitempty"`
	// ContentIv holds the value of the "contentIv" field.
	ContentIv []byte `json:"contentIv,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 NoteQuery when eager-loading is set.
	Edges       NoteEdges `json:"edges"`
	vault_notes *uuid.UUID
}

// NoteEdges holds the relations/edges for other nodes in the graph.
type NoteEdges struct {
	// 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 [1]bool
}

// 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 NoteEdges) VaultOrErr() (*Vault, error) {
	if e.loadedTypes[0] {
		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 (*Note) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case note.FieldName, note.FieldNameIv, note.FieldTitle, note.FieldTitleIv, note.FieldContent, note.FieldContentIv, note.FieldColour, note.FieldColourIv:
			values[i] = new([]byte)
		case note.FieldID:
			values[i] = new(uuid.UUID)
		case note.ForeignKeys[0]: // vault_notes
			values[i] = &sql.NullScanner{S: new(uuid.UUID)}
		default:
			return nil, fmt.Errorf("unexpected column %q for type Note", columns[i])
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Note fields.
func (n *Note) 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 note.FieldID:
			if value, ok := values[i].(*uuid.UUID); !ok {
				return fmt.Errorf("unexpected type %T for field id", values[i])
			} else if value != nil {
				n.ID = *value
			}
		case note.FieldName:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field name", values[i])
			} else if value != nil {
				n.Name = *value
			}
		case note.FieldNameIv:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field nameIv", values[i])
			} else if value != nil {
				n.NameIv = *value
			}
		case note.FieldTitle:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field title", values[i])
			} else if value != nil {
				n.Title = *value
			}
		case note.FieldTitleIv:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field titleIv", values[i])
			} else if value != nil {
				n.TitleIv = *value
			}
		case note.FieldContent:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field content", values[i])
			} else if value != nil {
				n.Content = *value
			}
		case note.FieldContentIv:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field contentIv", values[i])
			} else if value != nil {
				n.ContentIv = *value
			}
		case note.FieldColour:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field colour", values[i])
			} else if value != nil {
				n.Colour = *value
			}
		case note.FieldColourIv:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field colourIv", values[i])
			} else if value != nil {
				n.ColourIv = *value
			}
		case note.ForeignKeys[0]:
			if value, ok := values[i].(*sql.NullScanner); !ok {
				return fmt.Errorf("unexpected type %T for field vault_notes", values[i])
			} else if value.Valid {
				n.vault_notes = new(uuid.UUID)
				*n.vault_notes = *value.S.(*uuid.UUID)
			}
		}
	}
	return nil
}

// QueryVault queries the "vault" edge of the Note entity.
func (n *Note) QueryVault() *VaultQuery {
	return NewNoteClient(n.config).QueryVault(n)
}

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

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

// String implements the fmt.Stringer.
func (n *Note) String() string {
	var builder strings.Builder
	builder.WriteString("Note(")
	builder.WriteString(fmt.Sprintf("id=%v, ", n.ID))
	builder.WriteString("name=")
	builder.WriteString(fmt.Sprintf("%v", n.Name))
	builder.WriteString(", ")
	builder.WriteString("nameIv=")
	builder.WriteString(fmt.Sprintf("%v", n.NameIv))
	builder.WriteString(", ")
	builder.WriteString("title=")
	builder.WriteString(fmt.Sprintf("%v", n.Title))
	builder.WriteString(", ")
	builder.WriteString("titleIv=")
	builder.WriteString(fmt.Sprintf("%v", n.TitleIv))
	builder.WriteString(", ")
	builder.WriteString("content=")
	builder.WriteString(fmt.Sprintf("%v", n.Content))
	builder.WriteString(", ")
	builder.WriteString("contentIv=")
	builder.WriteString(fmt.Sprintf("%v", n.ContentIv))
	builder.WriteString(", ")
	builder.WriteString("colour=")
	builder.WriteString(fmt.Sprintf("%v", n.Colour))
	builder.WriteString(", ")
	builder.WriteString("colourIv=")
	builder.WriteString(fmt.Sprintf("%v", n.ColourIv))
	builder.WriteByte(')')
	return builder.String()
}

// Notes is a parsable slice of Note.
type Notes []*Note
