// Package models holds the plain structs shared between the db layer and // the HTTP handlers. Field tags do double duty: `db` for sqlx scanning, // `json` for API responses. package models import "time" type User struct { ID string `db:"id" json:"id"` OIDCSub string `db:"oidc_sub" json:"-"` Email string `db:"email" json:"email"` Name *string `db:"name" json:"name"` CreatedAt time.Time `db:"created_at" json:"createdAt"` } type Car struct { ID string `db:"id" json:"id"` UserID string `db:"user_id" json:"userId"` Rego string `db:"rego" json:"rego"` Make *string `db:"make" json:"make"` Model *string `db:"model" json:"model"` Year *int `db:"year" json:"year"` Color *string `db:"color" json:"color"` Odometer *int `db:"odometer" json:"odometer"` RegoExpiry *time.Time `db:"rego_expiry" json:"regoExpiry"` WofExpiry *time.Time `db:"wof_expiry" json:"wofExpiry"` PhotoS3Key *string `db:"photo_s3_key" json:"-"` HasPhoto bool `db:"-" json:"hasPhoto"` ShareToken *string `db:"share_token" json:"shareToken"` ServiceIntervalKM *int `db:"service_interval_km" json:"serviceIntervalKm"` ServiceIntervalMonths *int `db:"service_interval_months" json:"serviceIntervalMonths"` CreatedAt time.Time `db:"created_at" json:"createdAt"` UpdatedAt time.Time `db:"updated_at" json:"updatedAt"` } // CarInput is the JSON body accepted for car create/update requests. Share // links are managed separately (POST/DELETE .../share) since they're not // really "car info" the way these fields are. type CarInput struct { Rego string `json:"rego"` Make *string `json:"make"` Model *string `json:"model"` Year *int `json:"year"` Color *string `json:"color"` Odometer *int `json:"odometer"` RegoExpiry *string `json:"regoExpiry"` // "YYYY-MM-DD" or null WofExpiry *string `json:"wofExpiry"` ServiceIntervalKM *int `json:"serviceIntervalKm"` ServiceIntervalMonths *int `json:"serviceIntervalMonths"` } type ServiceEntry struct { ID string `db:"id" json:"id"` CarID string `db:"car_id" json:"carId"` EntryDate time.Time `db:"entry_date" json:"entryDate"` EntryType string `db:"entry_type" json:"entryType"` Description *string `db:"description" json:"description"` PerformedAt *string `db:"performed_at" json:"performedAt"` Odometer *int `db:"odometer" json:"odometer"` // IsService marks this entry as "a full service" — the baseline the // synthesized next-service-due reminder counts forward from, using the // car's configured ServiceIntervalKM/ServiceIntervalMonths. IsService bool `db:"is_service" json:"isService"` CreatedAt time.Time `db:"created_at" json:"createdAt"` } type ServiceEntryInput struct { EntryDate string `json:"entryDate"` EntryType string `json:"entryType"` Description *string `json:"description"` PerformedAt *string `json:"performedAt"` Odometer *int `json:"odometer"` IsService bool `json:"isService"` } type ServiceEntryFile struct { ID string `db:"id" json:"id"` ServiceEntryID string `db:"service_entry_id" json:"serviceEntryId"` S3Key string `db:"s3_key" json:"-"` FileName string `db:"file_name" json:"fileName"` ContentType string `db:"content_type" json:"contentType"` SizeBytes int64 `db:"size_bytes" json:"sizeBytes"` CreatedAt time.Time `db:"created_at" json:"createdAt"` } type Reminder struct { ID string `db:"id" json:"id"` CarID string `db:"car_id" json:"carId"` ReminderType string `db:"reminder_type" json:"reminderType"` Label *string `db:"label" json:"label"` DueDate *time.Time `db:"due_date" json:"dueDate"` DueOdometer *int `db:"due_odometer" json:"dueOdometer"` Notes *string `db:"notes" json:"notes"` CompletedAt *time.Time `db:"completed_at" json:"completedAt"` CreatedAt time.Time `db:"created_at" json:"createdAt"` } type ReminderInput struct { ReminderType string `json:"reminderType"` Label *string `json:"label"` DueDate *string `json:"dueDate"` DueOdometer *int `json:"dueOdometer"` Notes *string `json:"notes"` } type KnowledgeEntry struct { ID string `db:"id" json:"id"` CarID string `db:"car_id" json:"carId"` Title string `db:"title" json:"title"` Body string `db:"body" json:"body"` CreatedAt time.Time `db:"created_at" json:"createdAt"` UpdatedAt time.Time `db:"updated_at" json:"updatedAt"` } type KnowledgeEntryInput struct { Title string `json:"title"` Body string `json:"body"` } // ReminderView is the unified shape for every "reminder-like" row shown to // the user — real stored Reminder rows, plus rego/WoF expiry and next- // service-due items synthesized on the fly from the car's own fields (no // separate stored row to keep in sync). ID is nil for synthesized items, // which is how the frontend knows there's nothing to edit/delete/complete — // to change those, edit the car's rego/WoF/service-interval fields instead. // Used by both GET /api/dashboard (across all cars) and the car-scoped // GET /api/cars/{id}/reminders. type ReminderView struct { ID *string `db:"id" json:"id"` CarID string `db:"car_id" json:"carId"` CarRego string `db:"car_rego" json:"carRego"` ReminderType string `db:"reminder_type" json:"reminderType"` // 'service' | 'wheel_rotation' | 'alignment' | 'custom' | 'rego' | 'wof' Label *string `db:"label" json:"label"` DueDate *time.Time `db:"due_date" json:"dueDate"` DueOdometer *int `db:"due_odometer" json:"dueOdometer"` Notes *string `db:"notes" json:"notes"` CompletedAt *time.Time `db:"completed_at" json:"completedAt"` Status string `db:"status" json:"status"` // 'overdue' | 'upcoming' | 'future' | 'done' } type FuelEntry struct { ID string `db:"id" json:"id"` CarID string `db:"car_id" json:"carId"` EntryDate time.Time `db:"entry_date" json:"entryDate"` Litres float64 `db:"litres" json:"litres"` Cost float64 `db:"cost" json:"cost"` Odometer *int `db:"odometer" json:"odometer"` Location *string `db:"location" json:"location"` Notes *string `db:"notes" json:"notes"` CreatedAt time.Time `db:"created_at" json:"createdAt"` } type FuelEntryInput struct { EntryDate string `json:"entryDate"` Litres float64 `json:"litres"` Cost float64 `json:"cost"` Odometer *int `json:"odometer"` Location *string `json:"location"` Notes *string `json:"notes"` }