-- Enable foreign key constraints
PRAGMA foreign_keys = ON;

CREATE TABLE user (
    uuid TEXT PRIMARY KEY,
    name TEXT NOT NULL
);

CREATE TABLE camera (
    uuid TEXT PRIMARY KEY,
    desc TEXT,
    name TEXT NOT NULL
);

CREATE TABLE sightings (
    user_uuid TEXT NOT NULL,
    sighted_at DATETIME NOT NULL,
    camera_id TEXT NOT NULL,
    FOREIGN KEY (user_uuid) REFERENCES user(uuid) ON DELETE CASCADE ON UPDATE CASCADE,
    FOREIGN KEY (camera_id) REFERENCES camera(uuid) ON DELETE CASCADE ON UPDATE CASCADE,
    UNIQUE (user_uuid, camera_id)
);

-- Create indexes for better performance on foreign key lookups
CREATE INDEX idx_sightings_user_uuid ON sightings(user_uuid);
CREATE INDEX idx_sightings_camera_id ON sightings(camera_id);
