// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"
	"time"

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

// ReminderState is the model entity for the ReminderState schema.
type ReminderState struct {
	config `json:"-"`
	// ID of the ent.
	ID int `json:"id,omitempty"`
	// CalendarID holds the value of the "calendar_id" field.
	CalendarID string `json:"calendar_id,omitempty"`
	// UID holds the value of the "uid" field.
	UID string `json:"uid,omitempty"`
	// OccurrenceStart holds the value of the "occurrence_start" field.
	OccurrenceStart time.Time `json:"occurrence_start,omitempty"`
	// Minutes holds the value of the "minutes" field.
	Minutes int `json:"minutes,omitempty"`
	// FiredAt holds the value of the "fired_at" field.
	FiredAt time.Time `json:"fired_at,omitempty"`
	// SnoozedUntil holds the value of the "snoozed_until" field.
	SnoozedUntil *time.Time `json:"snoozed_until,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*ReminderState) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case reminderstate.FieldID, reminderstate.FieldMinutes:
			values[i] = new(sql.NullInt64)
		case reminderstate.FieldCalendarID, reminderstate.FieldUID:
			values[i] = new(sql.NullString)
		case reminderstate.FieldOccurrenceStart, reminderstate.FieldFiredAt, reminderstate.FieldSnoozedUntil:
			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 ReminderState fields.
func (_m *ReminderState) 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 reminderstate.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			_m.ID = int(value.Int64)
		case reminderstate.FieldCalendarID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field calendar_id", values[i])
			} else if value.Valid {
				_m.CalendarID = value.String
			}
		case reminderstate.FieldUID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field uid", values[i])
			} else if value.Valid {
				_m.UID = value.String
			}
		case reminderstate.FieldOccurrenceStart:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field occurrence_start", values[i])
			} else if value.Valid {
				_m.OccurrenceStart = value.Time
			}
		case reminderstate.FieldMinutes:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field minutes", values[i])
			} else if value.Valid {
				_m.Minutes = int(value.Int64)
			}
		case reminderstate.FieldFiredAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field fired_at", values[i])
			} else if value.Valid {
				_m.FiredAt = value.Time
			}
		case reminderstate.FieldSnoozedUntil:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field snoozed_until", values[i])
			} else if value.Valid {
				_m.SnoozedUntil = new(time.Time)
				*_m.SnoozedUntil = 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 ReminderState.
// This includes values selected through modifiers, order, etc.
func (_m *ReminderState) Value(name string) (ent.Value, error) {
	return _m.selectValues.Get(name)
}

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

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

// String implements the fmt.Stringer.
func (_m *ReminderState) String() string {
	var builder strings.Builder
	builder.WriteString("ReminderState(")
	builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
	builder.WriteString("calendar_id=")
	builder.WriteString(_m.CalendarID)
	builder.WriteString(", ")
	builder.WriteString("uid=")
	builder.WriteString(_m.UID)
	builder.WriteString(", ")
	builder.WriteString("occurrence_start=")
	builder.WriteString(_m.OccurrenceStart.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("minutes=")
	builder.WriteString(fmt.Sprintf("%v", _m.Minutes))
	builder.WriteString(", ")
	builder.WriteString("fired_at=")
	builder.WriteString(_m.FiredAt.Format(time.ANSIC))
	builder.WriteString(", ")
	if v := _m.SnoozedUntil; v != nil {
		builder.WriteString("snoozed_until=")
		builder.WriteString(v.Format(time.ANSIC))
	}
	builder.WriteByte(')')
	return builder.String()
}

// ReminderStates is a parsable slice of ReminderState.
type ReminderStates []*ReminderState
