CREATE TABLE `prompts` (
  `id` text PRIMARY KEY NOT NULL,
  `title` text NOT NULL,
  `content_image` text DEFAULT '',
  `content_video` text DEFAULT '',
  `translation_image` text,
  `translation_video` text,
  `tags` text DEFAULT '[]',
  `source_url` text,
  `is_favorite` integer DEFAULT 0,
  `created_at` integer NOT NULL,
  `updated_at` integer NOT NULL
);

CREATE INDEX `idx_prompts_updated` ON `prompts`(`updated_at`);
CREATE INDEX `idx_prompts_favorite` ON `prompts`(`is_favorite`);

CREATE TABLE `images` (
  `id` text PRIMARY KEY NOT NULL,
  `prompt_id` text NOT NULL,
  `b64` text NOT NULL,
  `model` text NOT NULL,
  `size` text NOT NULL,
  `quality` text NOT NULL,
  `generation_duration` integer NOT NULL,
  `prompt_used` text NOT NULL,
  `created_at` integer NOT NULL
);

CREATE INDEX `idx_images_prompt` ON `images`(`prompt_id`);

CREATE TABLE `settings` (
  `id` text PRIMARY KEY NOT NULL DEFAULT 'default',
  `openai_base_url` text DEFAULT 'https://api.openai.com/v1',
  `openai_api_key` text DEFAULT '',
  `image_model` text DEFAULT 'gpt-image-2',
  `translate_model` text DEFAULT 'gpt-4o-mini',
  `updated_at` integer NOT NULL
);

INSERT INTO `settings` (`id`, `updated_at`) VALUES ('default', 0);
