-- ============================================================================
-- BASE DE DATOS OFICIAL: SLOTH ART
-- Compatible con MySQL 5.7+ / 8.0+ y MariaDB 10.3+
-- ============================================================================

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";

-- ----------------------------------------------------------------------------
-- 1. TABLA DE USUARIOS ADMINISTRADORES
-- ----------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(50) NOT NULL,
  `password_hash` varchar(255) NOT NULL,
  `last_login` datetime DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ----------------------------------------------------------------------------
-- 2. TABLA DE CONFIGURACIÓN VISUAL Y GENERAL DEL SITIO
-- ----------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `site_settings` (
  `setting_key` varchar(100) NOT NULL,
  `setting_value` text NOT NULL,
  `setting_group` varchar(50) NOT NULL DEFAULT 'general',
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`setting_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Valores predeterminados fieles al boceto de SLOTH ART
INSERT INTO `site_settings` (`setting_key`, `setting_value`, `setting_group`) VALUES
('site_title', 'SLOTH ART', 'header'),
('site_subtitle', 'Estudio Creativo & Portafolio Digital', 'header'),
('color_header_bg', '#000000', 'colors'),
('color_header_text', '#ffffff', 'colors'),
('color_blue_start', '#2b589b', 'colors'),
('color_blue_end', '#7aa5db', 'colors'),
('color_nav_dark', '#162f56', 'colors'),
('color_page_bg', '#ffffff', 'colors'),
('color_card_bg', '#ffffff', 'colors'),
('color_text_main', '#111111', 'colors'),
('color_text_muted', '#555555', 'colors'),
('color_cta_bar_bg', '#000000', 'colors'),
('color_cta_btn_bg', '#ffffff', 'colors'),
('color_cta_btn_text', '#000000', 'colors'),
('font_heading', 'Anton', 'typography'),
('font_body', 'Montserrat', 'typography'),
('size_hero_title', '4.2', 'typography'),
('size_body_text', '1.0', 'typography'),
('card_radius', '6', 'layout'),
('btn_radius', '50', 'layout'),
('section_spacing', '40', 'layout'),
('animation_speed', '0.3', 'layout'),
('carousel_autoplay', '1', 'carousel'),
('carousel_interval', '5000', 'carousel'),
('currency_symbol', '$', 'general'),
('footer_text', '© SLOTH ART — Todos los derechos reservados.', 'general')
ON DUPLICATE KEY UPDATE `setting_value` = VALUES(`setting_value`);

-- ----------------------------------------------------------------------------
-- 3. TABLA DE RECURSOS GRÁFICOS (LOGOTIPO, FAVICON, EXTRAS)
-- ----------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `assets` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `asset_type` enum('logo','favicon','other') NOT NULL,
  `file_path` varchar(255) NOT NULL,
  `alt_text` varchar(150) DEFAULT 'SLOTH ART',
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ----------------------------------------------------------------------------
-- 4. TABLA DE BANNERS DEL CARRUSEL PRINCIPAL
-- ----------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `banners` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(150) DEFAULT '',
  `subtitle` text,
  `image_path` varchar(255) NOT NULL,
  `link_url` varchar(255) DEFAULT '',
  `sort_order` int(11) NOT NULL DEFAULT 0,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ----------------------------------------------------------------------------
-- 5. TABLA DE CATEGORÍAS DE SERVICIOS
-- ----------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `categories` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  `slug` varchar(100) NOT NULL,
  `sort_order` int(11) NOT NULL DEFAULT 0,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `slug` (`slug`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Categorías iniciales exactas del boceto
INSERT INTO `categories` (`id`, `name`, `slug`, `sort_order`, `is_active`) VALUES
(1, 'Publicidad', 'publicidad', 1, 1),
(2, 'Fotografía', 'fotografia', 2, 1),
(3, 'Maquetación', 'maquetacion', 3, 1),
(4, 'Desarrollo web', 'desarrollo-web', 4, 1),
(5, 'Dibujo', 'dibujo', 5, 1),
(6, 'Ilustración', 'ilustracion', 6, 1),
(7, 'Edición de videos', 'edicion-de-videos', 7, 1)
ON DUPLICATE KEY UPDATE `name` = VALUES(`name`);

-- ----------------------------------------------------------------------------
-- 6. TABLA DE PRODUCTOS Y SERVICIOS
-- ----------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `products` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `category_id` int(11) NOT NULL,
  `title` varchar(150) NOT NULL,
  `caption` varchar(255) DEFAULT '',
  `description` text,
  `main_image` varchar(255) NOT NULL,
  `price` decimal(10,2) NOT NULL DEFAULT 0.00,
  `availability` enum('DISPONIBLE','AGOTADO') NOT NULL DEFAULT 'DISPONIBLE',
  `status` enum('PUBLICADO','BORRADOR') NOT NULL DEFAULT 'PUBLICADO',
  `sort_order` int(11) NOT NULL DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `fk_products_category` (`category_id`),
  CONSTRAINT `fk_products_category` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ----------------------------------------------------------------------------
-- 7. TABLA DE FOTOGRAFÍAS ADICIONALES POR PRODUCTO
-- ----------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `product_images` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `product_id` int(11) NOT NULL,
  `image_path` varchar(255) NOT NULL,
  `sort_order` int(11) NOT NULL DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `fk_images_product` (`product_id`),
  CONSTRAINT `fk_images_product` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

COMMIT;