-- =====================================================
-- Site Watermark Settings Table
-- =====================================================
-- This table stores site-wide watermark configuration
-- that applies to all users and content on the platform

CREATE TABLE IF NOT EXISTS `site_watermark_settings` (
  `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `site_id` int(11) NOT NULL DEFAULT 1 COMMENT 'Site identifier for multi-site support',
  `site_watermark_enabled` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Enable/disable site-wide watermarking',
  `watermark_policy` enum('mandatory','optional','disabled') NOT NULL DEFAULT 'optional' COMMENT 'Site watermark policy',
  `allow_user_override` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Allow users to override site watermark settings',
  `default_watermark_path` varchar(500) DEFAULT NULL COMMENT 'Path to default site watermark image',
  `default_watermark_text` varchar(255) DEFAULT 'Protected Content' COMMENT 'Default watermark text',
  `default_watermark_position` varchar(50) DEFAULT 'bottom-right' COMMENT 'Default watermark position',
  `default_watermark_opacity` int(11) DEFAULT 70 COMMENT 'Default watermark opacity (10-100)',
  `enable_dmca_protection` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Enable additional DMCA protection watermark',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_site_id` (`site_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Site-wide watermark configuration settings';

-- Insert default site watermark settings
INSERT IGNORE INTO `site_watermark_settings` (
  `site_id`,
  `site_watermark_enabled`,
  `watermark_policy`,
  `allow_user_override`,
  `default_watermark_text`,
  `default_watermark_position`,
  `default_watermark_opacity`,
  `enable_dmca_protection`
) VALUES (
  1,
  1,
  'optional',
  1,
  'Protected Content',
  'bottom-right',
  70,
  0
);

-- =====================================================
-- Watermark Processing Jobs Table
-- =====================================================
-- This table tracks watermark processing jobs for monitoring

CREATE TABLE IF NOT EXISTS `watermark_processing_jobs` (
  `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) UNSIGNED DEFAULT NULL,
  `admin_id` bigint(20) UNSIGNED DEFAULT NULL,
  `job_type` enum('single','bulk_all','bulk_new','bulk_user') NOT NULL DEFAULT 'single',
  `target_user_id` bigint(20) UNSIGNED DEFAULT NULL COMMENT 'For bulk_user jobs',
  `media_id` bigint(20) UNSIGNED DEFAULT NULL COMMENT 'For single media jobs',
  `status` enum('pending','processing','completed','failed') NOT NULL DEFAULT 'pending',
  `progress` int(11) DEFAULT 0 COMMENT 'Progress percentage (0-100)',
  `total_items` int(11) DEFAULT 0 COMMENT 'Total items to process',
  `processed_items` int(11) DEFAULT 0 COMMENT 'Items processed so far',
  `error_message` text DEFAULT NULL,
  `started_at` timestamp NULL DEFAULT NULL,
  `completed_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_user_id` (`user_id`),
  KEY `idx_admin_id` (`admin_id`),
  KEY `idx_status` (`status`),
  KEY `idx_job_type` (`job_type`),
  KEY `idx_created_at` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Watermark processing job tracking';