// 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/calendar"
	"github.com/AvengeMedia/dankcalendar/core/ent/event"
)

// Event is the model entity for the Event schema.
type Event struct {
	config `json:"-"`
	// ID of the ent.
	ID string `json:"id,omitempty"`
	// UID holds the value of the "uid" field.
	UID string `json:"uid,omitempty"`
	// RemoteID holds the value of the "remote_id" field.
	RemoteID string `json:"remote_id,omitempty"`
	// Etag holds the value of the "etag" field.
	Etag string `json:"etag,omitempty"`
	// Summary holds the value of the "summary" field.
	Summary string `json:"summary,omitempty"`
	// Description holds the value of the "description" field.
	Description string `json:"description,omitempty"`
	// Location holds the value of the "location" field.
	Location string `json:"location,omitempty"`
	// URL holds the value of the "url" field.
	URL string `json:"url,omitempty"`
	// MeetingURL holds the value of the "meeting_url" field.
	MeetingURL string `json:"meeting_url,omitempty"`
	// Status holds the value of the "status" field.
	Status event.Status `json:"status,omitempty"`
	// Start holds the value of the "start" field.
	Start time.Time `json:"start,omitempty"`
	// End holds the value of the "end" field.
	End time.Time `json:"end,omitempty"`
	// AllDay holds the value of the "all_day" field.
	AllDay bool `json:"all_day,omitempty"`
	// StartTz holds the value of the "start_tz" field.
	StartTz string `json:"start_tz,omitempty"`
	// EndTz holds the value of the "end_tz" field.
	EndTz string `json:"end_tz,omitempty"`
	// Recurrence holds the value of the "recurrence" field.
	Recurrence map[string]interface{} `json:"recurrence,omitempty"`
	// RecurringID holds the value of the "recurring_id" field.
	RecurringID string `json:"recurring_id,omitempty"`
	// OriginalStart holds the value of the "original_start" field.
	OriginalStart *time.Time `json:"original_start,omitempty"`
	// Organizer holds the value of the "organizer" field.
	Organizer map[string]interface{} `json:"organizer,omitempty"`
	// Attendees holds the value of the "attendees" field.
	Attendees []map[string]interface{} `json:"attendees,omitempty"`
	// Reminders holds the value of the "reminders" field.
	Reminders []map[string]interface{} `json:"reminders,omitempty"`
	// Categories holds the value of the "categories" field.
	Categories []string `json:"categories,omitempty"`
	// Transparency holds the value of the "transparency" field.
	Transparency string `json:"transparency,omitempty"`
	// Visibility holds the value of the "visibility" field.
	Visibility string `json:"visibility,omitempty"`
	// RawIcs holds the value of the "raw_ics" field.
	RawIcs string `json:"raw_ics,omitempty"`
	// Created holds the value of the "created" field.
	Created time.Time `json:"created,omitempty"`
	// Updated holds the value of the "updated" field.
	Updated time.Time `json:"updated,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the EventQuery when eager-loading is set.
	Edges           EventEdges `json:"edges"`
	calendar_events *string
	selectValues    sql.SelectValues
}

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

// CalendarOrErr returns the Calendar value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e EventEdges) CalendarOrErr() (*Calendar, error) {
	if e.Calendar != nil {
		return e.Calendar, nil
	} else if e.loadedTypes[0] {
		return nil, &NotFoundError{label: calendar.Label}
	}
	return nil, &NotLoadedError{edge: "calendar"}
}

// scanValues returns the types for scanning values from sql.Rows.
func (*Event) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case event.FieldRecurrence, event.FieldOrganizer, event.FieldAttendees, event.FieldReminders, event.FieldCategories:
			values[i] = new([]byte)
		case event.FieldAllDay:
			values[i] = new(sql.NullBool)
		case event.FieldID, event.FieldUID, event.FieldRemoteID, event.FieldEtag, event.FieldSummary, event.FieldDescription, event.FieldLocation, event.FieldURL, event.FieldMeetingURL, event.FieldStatus, event.FieldStartTz, event.FieldEndTz, event.FieldRecurringID, event.FieldTransparency, event.FieldVisibility, event.FieldRawIcs:
			values[i] = new(sql.NullString)
		case event.FieldStart, event.FieldEnd, event.FieldOriginalStart, event.FieldCreated, event.FieldUpdated:
			values[i] = new(sql.NullTime)
		case event.ForeignKeys[0]: // calendar_events
			values[i] = new(sql.NullString)
		default:
			values[i] = new(sql.UnknownType)
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Event fields.
func (_m *Event) 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 event.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 event.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 event.FieldRemoteID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field remote_id", values[i])
			} else if value.Valid {
				_m.RemoteID = value.String
			}
		case event.FieldEtag:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field etag", values[i])
			} else if value.Valid {
				_m.Etag = value.String
			}
		case event.FieldSummary:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field summary", values[i])
			} else if value.Valid {
				_m.Summary = value.String
			}
		case event.FieldDescription:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field description", values[i])
			} else if value.Valid {
				_m.Description = value.String
			}
		case event.FieldLocation:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field location", values[i])
			} else if value.Valid {
				_m.Location = value.String
			}
		case event.FieldURL:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field url", values[i])
			} else if value.Valid {
				_m.URL = value.String
			}
		case event.FieldMeetingURL:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field meeting_url", values[i])
			} else if value.Valid {
				_m.MeetingURL = value.String
			}
		case event.FieldStatus:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				_m.Status = event.Status(value.String)
			}
		case event.FieldStart:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field start", values[i])
			} else if value.Valid {
				_m.Start = value.Time
			}
		case event.FieldEnd:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field end", values[i])
			} else if value.Valid {
				_m.End = value.Time
			}
		case event.FieldAllDay:
			if value, ok := values[i].(*sql.NullBool); !ok {
				return fmt.Errorf("unexpected type %T for field all_day", values[i])
			} else if value.Valid {
				_m.AllDay = value.Bool
			}
		case event.FieldStartTz:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field start_tz", values[i])
			} else if value.Valid {
				_m.StartTz = value.String
			}
		case event.FieldEndTz:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field end_tz", values[i])
			} else if value.Valid {
				_m.EndTz = value.String
			}
		case event.FieldRecurrence:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field recurrence", values[i])
			} else if value != nil && len(*value) > 0 {
				if err := json.Unmarshal(*value, &_m.Recurrence); err != nil {
					return fmt.Errorf("unmarshal field recurrence: %w", err)
				}
			}
		case event.FieldRecurringID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field recurring_id", values[i])
			} else if value.Valid {
				_m.RecurringID = value.String
			}
		case event.FieldOriginalStart:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field original_start", values[i])
			} else if value.Valid {
				_m.OriginalStart = new(time.Time)
				*_m.OriginalStart = value.Time
			}
		case event.FieldOrganizer:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field organizer", values[i])
			} else if value != nil && len(*value) > 0 {
				if err := json.Unmarshal(*value, &_m.Organizer); err != nil {
					return fmt.Errorf("unmarshal field organizer: %w", err)
				}
			}
		case event.FieldAttendees:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field attendees", values[i])
			} else if value != nil && len(*value) > 0 {
				if err := json.Unmarshal(*value, &_m.Attendees); err != nil {
					return fmt.Errorf("unmarshal field attendees: %w", err)
				}
			}
		case event.FieldReminders:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field reminders", values[i])
			} else if value != nil && len(*value) > 0 {
				if err := json.Unmarshal(*value, &_m.Reminders); err != nil {
					return fmt.Errorf("unmarshal field reminders: %w", err)
				}
			}
		case event.FieldCategories:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field categories", values[i])
			} else if value != nil && len(*value) > 0 {
				if err := json.Unmarshal(*value, &_m.Categories); err != nil {
					return fmt.Errorf("unmarshal field categories: %w", err)
				}
			}
		case event.FieldTransparency:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field transparency", values[i])
			} else if value.Valid {
				_m.Transparency = value.String
			}
		case event.FieldVisibility:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field visibility", values[i])
			} else if value.Valid {
				_m.Visibility = value.String
			}
		case event.FieldRawIcs:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field raw_ics", values[i])
			} else if value.Valid {
				_m.RawIcs = value.String
			}
		case event.FieldCreated:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field created", values[i])
			} else if value.Valid {
				_m.Created = value.Time
			}
		case event.FieldUpdated:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field updated", values[i])
			} else if value.Valid {
				_m.Updated = value.Time
			}
		case event.ForeignKeys[0]:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field calendar_events", values[i])
			} else if value.Valid {
				_m.calendar_events = new(string)
				*_m.calendar_events = value.String
			}
		default:
			_m.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

// Value returns the ent.Value that was dynamically selected and assigned to the Event.
// This includes values selected through modifiers, order, etc.
func (_m *Event) Value(name string) (ent.Value, error) {
	return _m.selectValues.Get(name)
}

// QueryCalendar queries the "calendar" edge of the Event entity.
func (_m *Event) QueryCalendar() *CalendarQuery {
	return NewEventClient(_m.config).QueryCalendar(_m)
}

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

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

// String implements the fmt.Stringer.
func (_m *Event) String() string {
	var builder strings.Builder
	builder.WriteString("Event(")
	builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
	builder.WriteString("uid=")
	builder.WriteString(_m.UID)
	builder.WriteString(", ")
	builder.WriteString("remote_id=")
	builder.WriteString(_m.RemoteID)
	builder.WriteString(", ")
	builder.WriteString("etag=")
	builder.WriteString(_m.Etag)
	builder.WriteString(", ")
	builder.WriteString("summary=")
	builder.WriteString(_m.Summary)
	builder.WriteString(", ")
	builder.WriteString("description=")
	builder.WriteString(_m.Description)
	builder.WriteString(", ")
	builder.WriteString("location=")
	builder.WriteString(_m.Location)
	builder.WriteString(", ")
	builder.WriteString("url=")
	builder.WriteString(_m.URL)
	builder.WriteString(", ")
	builder.WriteString("meeting_url=")
	builder.WriteString(_m.MeetingURL)
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(fmt.Sprintf("%v", _m.Status))
	builder.WriteString(", ")
	builder.WriteString("start=")
	builder.WriteString(_m.Start.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("end=")
	builder.WriteString(_m.End.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("all_day=")
	builder.WriteString(fmt.Sprintf("%v", _m.AllDay))
	builder.WriteString(", ")
	builder.WriteString("start_tz=")
	builder.WriteString(_m.StartTz)
	builder.WriteString(", ")
	builder.WriteString("end_tz=")
	builder.WriteString(_m.EndTz)
	builder.WriteString(", ")
	builder.WriteString("recurrence=")
	builder.WriteString(fmt.Sprintf("%v", _m.Recurrence))
	builder.WriteString(", ")
	builder.WriteString("recurring_id=")
	builder.WriteString(_m.RecurringID)
	builder.WriteString(", ")
	if v := _m.OriginalStart; v != nil {
		builder.WriteString("original_start=")
		builder.WriteString(v.Format(time.ANSIC))
	}
	builder.WriteString(", ")
	builder.WriteString("organizer=")
	builder.WriteString(fmt.Sprintf("%v", _m.Organizer))
	builder.WriteString(", ")
	builder.WriteString("attendees=")
	builder.WriteString(fmt.Sprintf("%v", _m.Attendees))
	builder.WriteString(", ")
	builder.WriteString("reminders=")
	builder.WriteString(fmt.Sprintf("%v", _m.Reminders))
	builder.WriteString(", ")
	builder.WriteString("categories=")
	builder.WriteString(fmt.Sprintf("%v", _m.Categories))
	builder.WriteString(", ")
	builder.WriteString("transparency=")
	builder.WriteString(_m.Transparency)
	builder.WriteString(", ")
	builder.WriteString("visibility=")
	builder.WriteString(_m.Visibility)
	builder.WriteString(", ")
	builder.WriteString("raw_ics=")
	builder.WriteString(_m.RawIcs)
	builder.WriteString(", ")
	builder.WriteString("created=")
	builder.WriteString(_m.Created.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated=")
	builder.WriteString(_m.Updated.Format(time.ANSIC))
	builder.WriteByte(')')
	return builder.String()
}

// Events is a parsable slice of Event.
type Events []*Event
