CREATE TABLE IF NOT EXISTS jobs (
  id TEXT PRIMARY KEY,
  type TEXT NOT NULL DEFAULT 'encode',
  url TEXT,
  file_path TEXT,
  original_file_name TEXT,
  output_file_name TEXT,
  status TEXT NOT NULL DEFAULT 'pending',
  progress INTEGER DEFAULT 0,
  current_step TEXT,
  resolution TEXT DEFAULT 'all',
  series_name TEXT,
  batch_index INTEGER DEFAULT 0,
  batch_total INTEGER DEFAULT 0,
  file_info TEXT,
  output_files TEXT,
  gdrive_folder_id TEXT,
  gdrive_folder_name TEXT,
  gdrive_file_ids TEXT,
  log TEXT DEFAULT '',
  error TEXT,
  created_at TEXT DEFAULT (datetime('now')),
  updated_at TEXT DEFAULT (datetime('now'))
);

CREATE TABLE IF NOT EXISTS settings (
  key TEXT PRIMARY KEY,
  value TEXT NOT NULL,
  updated_at TEXT DEFAULT (datetime('now'))
);

-- Default settings
INSERT OR IGNORE INTO settings (key, value) VALUES
  ('general', '{"siteName":"MovieHubBD","adminPassword":"admin123","downloadDir":"./data/downloads","tempDir":"./data/temp","outputDir":"./data/output","maxConcurrentJobs":2}'),
  ('metadata_template', '{"videoTrackName":"Video | {siteName}","audioTrackName":"Audio | {siteName}","subTrackName":"Subtitle | {siteName}","globalTitle":"{fileName} | {siteName}","globalComment":"{siteName}.online","encoderTag":"FFmpeg | {siteName}","language":"und"}'),
  ('encoding_presets', '{"enabled480p":true,"enabled720p":true,"enabled1080p":true,"crf480":28,"crf720":24,"crf1080":22,"videoCodec":"libx264","preset":"fast","audioCodec":"aac","audioBitrate":"192k","outputFormat":"mkv","stripAttachments":true}'),
  ('gdrive', '{"clientId":"","clientSecret":"","refreshToken":"","rootFolderId":"","connected":false}');
