CREATE TABLE IF NOT EXISTS animal_photos (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  animal_id INTEGER NOT NULL,
  filename TEXT NOT NULL,
  original_name TEXT,
  mime TEXT,
  size_bytes INTEGER,
  is_primary INTEGER DEFAULT 0,
  is_public INTEGER NOT NULL DEFAULT 1,
  created_at TEXT DEFAULT (datetime('now'))
);

CREATE INDEX IF NOT EXISTS idx_animal_photos_animal ON animal_photos(animal_id);

CREATE TABLE IF NOT EXISTS medical_photos (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  animal_id INTEGER NOT NULL,
  medical_note_id INTEGER NOT NULL,
  filename TEXT NOT NULL,
  created_at TEXT DEFAULT (datetime('now')),
  FOREIGN KEY(animal_id) REFERENCES animals(id),
  FOREIGN KEY(medical_note_id) REFERENCES medical_notes(id)
);

CREATE INDEX IF NOT EXISTS idx_medical_photos_animal ON medical_photos(animal_id);
CREATE INDEX IF NOT EXISTS idx_medical_photos_note ON medical_photos(medical_note_id);
