-- Migration: Create services table
-- Description: Stores all available SMM services (followers, likes, etc.)
-- Date: 2026-01-26

CREATE TABLE IF NOT EXISTS services (
  id INT AUTO_INCREMENT PRIMARY KEY,
  category_id INT NOT NULL,
  api_provider_id INT NOT NULL,
  api_service_id VARCHAR(255) NOT NULL,
  name VARCHAR(255) NOT NULL,
  description TEXT,
  price DECIMAL(10, 4) DEFAULT 0,
  min_quantity INT DEFAULT 10,
  max_quantity INT DEFAULT 100000,
  type VARCHAR(50) DEFAULT 'Default',
  status ENUM('active', 'inactive') DEFAULT 'active',
  extra_data JSON,
  synced_at TIMESTAMP NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

  UNIQUE KEY unique_service_provider (api_service_id, api_provider_id),
  FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE CASCADE,
  FOREIGN KEY (api_provider_id) REFERENCES api_providers(id) ON DELETE CASCADE,

  INDEX idx_category_id (category_id),
  INDEX idx_provider_id (api_provider_id),
  INDEX idx_status (status),
  INDEX idx_api_service_id (api_service_id),
  INDEX idx_name (name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
