107 lines
3.1 KiB
Go
107 lines
3.1 KiB
Go
package database
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
var (
|
|
ErrNotFound = errors.New("entity not found")
|
|
ErrAlreadyExists = errors.New("entity already exists")
|
|
)
|
|
|
|
// User represents a Jules user.
|
|
type User struct {
|
|
ID uuid.UUID
|
|
PreferredChat string
|
|
Language string
|
|
Timezone string
|
|
}
|
|
|
|
// Chat links a user to an external messaging platform.
|
|
type Chat struct {
|
|
UserID uuid.UUID
|
|
Platform string // "telegram", "email", "whatsapp"
|
|
Identifier string // @username, email, phone
|
|
}
|
|
|
|
// Metadata stores facts Jules knows about a user.
|
|
type Metadata struct {
|
|
ID uuid.UUID
|
|
UserID uuid.UUID
|
|
CreatedAt time.Time
|
|
Value string
|
|
}
|
|
|
|
// Contact represents a relationship between two Jules users.
|
|
type Contact struct {
|
|
OwnerID uuid.UUID // User who owns this contact
|
|
TargetID uuid.UUID // Target user ID
|
|
Name string // "mom", "brother", "Lena"
|
|
}
|
|
|
|
// Notification is a scheduled reminder or check-in.
|
|
type Notification struct {
|
|
ID uuid.UUID
|
|
UserID uuid.UUID
|
|
ScheduledAt time.Time
|
|
Content string // "call mom", "morning workout", "make a compliment", "talk to random person"
|
|
}
|
|
|
|
// Action records an interaction between Jules and a user.
|
|
type Action struct {
|
|
ID uuid.UUID
|
|
UserID uuid.UUID
|
|
Type string // "user_msg", "jules_msg", "call", "ping_contact"
|
|
Content string
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
// Users manages user persistence.
|
|
type Users interface {
|
|
Create(ctx context.Context) (*User, error)
|
|
Get(ctx context.Context, id uuid.UUID) (*User, error)
|
|
Update(ctx context.Context, user *User) error
|
|
Delete(ctx context.Context, id uuid.UUID) error
|
|
}
|
|
|
|
// Chats manages chat persistence.
|
|
type Chats interface {
|
|
Attach(ctx context.Context, userID uuid.UUID, platform, identifier string) error
|
|
GetUserID(ctx context.Context, platform, identifier string) (uuid.UUID, error)
|
|
List(ctx context.Context, userID uuid.UUID) ([]Chat, error)
|
|
Detach(ctx context.Context, userID uuid.UUID, platform string) error
|
|
}
|
|
|
|
// MetadataStore manages metadata persistence.
|
|
type MetadataStore interface {
|
|
Add(ctx context.Context, userID uuid.UUID, value string) error
|
|
List(ctx context.Context, userID uuid.UUID) ([]Metadata, error)
|
|
Delete(ctx context.Context, id uuid.UUID) error
|
|
DeleteOlderThan(ctx context.Context, userID uuid.UUID, t time.Time) error
|
|
}
|
|
|
|
// Contacts manages contact persistence.
|
|
type Contacts interface {
|
|
Add(ctx context.Context, contact *Contact) error
|
|
Get(ctx context.Context, ownerID uuid.UUID, name string) (*Contact, error)
|
|
List(ctx context.Context, ownerID uuid.UUID) ([]Contact, error)
|
|
Delete(ctx context.Context, ownerID uuid.UUID, name string) error
|
|
}
|
|
|
|
// Notifications manages the notification queue.
|
|
type Notifications interface {
|
|
Push(ctx context.Context, n *Notification) error
|
|
Pop(ctx context.Context, limit int) ([]Notification, error)
|
|
}
|
|
|
|
// Actions manages the action log.
|
|
type Actions interface {
|
|
Log(ctx context.Context, a *Action) error
|
|
Recent(ctx context.Context, userID uuid.UUID, limit int) ([]Action, error)
|
|
DeleteOlderThan(ctx context.Context, userID uuid.UUID, t time.Time) error
|
|
}
|