-- https://www.phpmyadmin.net/
--
-- Tempo de geração: 29/05/2026 às 20:23
-- Versão do servidor: 10.4.32-MariaDB
-- Versão do PHP: 8.2.12

START TRANSACTION;



-- --------------------------------------------------------

--
-- Estrutura para tabela `events`
--

CREATE TABLE `events` (
  `id` int(11) NOT NULL,
  `slug` varchar(180) NOT NULL,
  `title` varchar(180) NOT NULL,
  `description` text DEFAULT NULL,
  `category` varchar(100) DEFAULT NULL,
  `event_date` datetime NOT NULL,
  `time_label` varchar(50) DEFAULT NULL,
  `location_label` varchar(180) DEFAULT NULL,
  `image_url` text DEFAULT NULL,
  `status` enum('active','featured','sold_out','finished','draft','last_tickets') NOT NULL DEFAULT 'draft',
  `featured` tinyint(1) NOT NULL DEFAULT 0,
  `total_tickets` int(11) DEFAULT NULL,
  `attractions_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`attractions_json`)),
  `internal_notes` text DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Despejando dados para a tabela `events`
--

INSERT INTO `events` (`id`, `slug`, `title`, `description`, `category`, `event_date`, `time_label`, `location_label`, `image_url`, `status`, `featured`, `total_tickets`, `attractions_json`, `internal_notes`, `created_at`, `updated_at`) VALUES
(5, 'bail-ao', 'Bailão', '', 'SHOW', '2026-05-29 12:00:00', '12:00', 'Paraju / Domingos Martins - ES', '/uploads/499590839-18021494816651395-7453057703159795787-n-2c5c754c5c.jpg', 'active', 1, NULL, '[\"neguinho safadão\",\"Anitta\",\"Alok\"]', '', '2026-05-29 14:13:53', '2026-05-29 14:27:21');

-- --------------------------------------------------------

--
-- Estrutura para tabela `event_batches`
--

CREATE TABLE `event_batches` (
  `id` int(11) NOT NULL,
  `event_id` int(11) NOT NULL,
  `code` varchar(80) NOT NULL,
  `name` varchar(150) NOT NULL,
  `description` varchar(255) DEFAULT NULL,
  `price` decimal(10,2) NOT NULL,
  `tickets_per_unit` int(11) NOT NULL DEFAULT 1,
  `quantity` int(11) DEFAULT NULL,
  `sold` int(11) NOT NULL DEFAULT 0,
  `is_available` tinyint(1) NOT NULL DEFAULT 1,
  `status` enum('active','sold_out','paused') NOT NULL DEFAULT 'active',
  `start_date` datetime DEFAULT NULL,
  `end_date` datetime DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Despejando dados para a tabela `event_batches`
--

INSERT INTO `event_batches` (`id`, `event_id`, `code`, `name`, `description`, `price`, `tickets_per_unit`, `quantity`, `sold`, `is_available`, `status`, `start_date`, `end_date`, `created_at`, `updated_at`) VALUES
(9, 5, 'lote-unico', 'Lote Unico', 'Lote vigente', 100.00, 1, NULL, 0, 1, 'active', NULL, NULL, '2026-05-29 14:13:53', '2026-05-29 14:27:21');

-- --------------------------------------------------------

--
-- Estrutura para tabela `gallery_images`
--

CREATE TABLE `gallery_images` (
  `id` int(11) NOT NULL,
  `image_url` text NOT NULL,
  `source_type` enum('instagram','upload') NOT NULL DEFAULT 'upload',
  `title` varchar(180) DEFAULT NULL,
  `display_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()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Despejando dados para a tabela `gallery_images`
--

INSERT INTO `gallery_images` (`id`, `image_url`, `source_type`, `title`, `display_order`, `created_at`, `updated_at`) VALUES
(1, 'https://images.unsplash.com/photo-1555396273-367ea4eb4db5?auto=format&fit=crop&q=80', 'instagram', 'Ambiente do salÒo', 0, '2026-05-29 03:52:20', '2026-05-29 04:54:13'),
(2, 'https://images.unsplash.com/photo-1514933651103-005eec06c04b?auto=format&fit=crop&q=80', 'instagram', 'Bar e atendimento', 1, '2026-05-29 03:52:20', '2026-05-29 04:54:13'),
(3, 'https://images.unsplash.com/photo-1528605248644-14dd04022da1?auto=format&fit=crop&q=80', 'instagram', 'Mesa para grupos', 2, '2026-05-29 03:52:20', '2026-05-29 04:54:13'),
(4, 'https://images.unsplash.com/photo-1510812431401-41d2bd2722f3?auto=format&fit=crop&q=80', 'upload', 'M·sica ambiente', 0, '2026-05-29 03:52:20', '2026-05-29 04:54:13'),
(5, 'https://images.unsplash.com/photo-1513558161293-cdaf765ed2fd?auto=format&fit=crop&q=80', 'upload', 'Bebidas selecionadas', 1, '2026-05-29 03:52:20', '2026-05-29 04:54:13'),
(6, 'https://images.unsplash.com/photo-1544148103-0773bf10d330?auto=format&fit=crop&q=80', 'upload', 'Buffet no GalpÒo Imperial', 2, '2026-05-29 03:52:20', '2026-05-29 04:44:51'),
(7, 'https://images.unsplash.com/photo-1510812431401-41d2bd2722f3?auto=format&fit=crop&q=80', 'upload', 'Bar do GalpÒo Imperial', 3, '2026-05-29 03:52:20', '2026-05-29 04:44:51'),
(8, 'https://images.unsplash.com/photo-1528605248644-14dd04022da1?auto=format&fit=crop&q=80', 'upload', 'Mesas para grupos', 4, '2026-05-29 03:52:20', '2026-05-29 04:44:51'),
(12, 'https://i.imgur.com/rVW7bRO.jpeg', 'upload', 'Bailão do Galpão Imperial', 2, '2026-05-29 04:55:32', '2026-05-29 04:55:32'),
(13, 'https://i.imgur.com/tBXQXBV.jpeg', 'upload', 'Gravação do DVD', 3, '2026-05-29 04:55:32', '2026-05-29 04:55:32'),
(14, 'https://i.imgur.com/3GQxe4t.jpeg', 'upload', 'Cavalgada Galpão Imperial', 4, '2026-05-29 04:55:32', '2026-05-29 04:55:32');

-- --------------------------------------------------------

--
-- Estrutura para tabela `gift_claims`
--

CREATE TABLE `gift_claims` (
  `id` int(11) NOT NULL,
  `first_name` varchar(100) NOT NULL,
  `last_name` varchar(100) NOT NULL,
  `cpf` varchar(20) DEFAULT NULL,
  `whatsapp` varchar(30) NOT NULL,
  `claim_code` varchar(80) NOT NULL,
  `status` enum('confirmed','used','cancelled') NOT NULL DEFAULT 'confirmed',
  `claim_date` datetime NOT NULL,
  `used_at` datetime DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Despejando dados para a tabela `gift_claims`
--

INSERT INTO `gift_claims` (`id`, `first_name`, `last_name`, `cpf`, `whatsapp`, `claim_code`, `status`, `claim_date`, `used_at`, `created_at`, `updated_at`) VALUES
(1, 'Mariana', 'Souza', NULL, '27999887766', 'PRESENTE-MARIANA-1234', 'confirmed', '2026-04-20 10:00:00', NULL, '2026-05-29 03:52:20', '2026-05-29 03:52:20'),
(2, 'Carla', 'Mendes', NULL, '27988776655', 'PRESENTE-CARLA-5678', 'used', '2026-04-21 15:30:00', '2026-04-22 21:00:00', '2026-05-29 03:52:20', '2026-05-29 03:52:20');

-- --------------------------------------------------------

--
-- Estrutura para tabela `hero_banners`
--

CREATE TABLE `hero_banners` (
  `id` int(11) NOT NULL,
  `title` varchar(180) NOT NULL,
  `subtitle` varchar(255) DEFAULT NULL,
  `description` text DEFAULT NULL,
  `image_url` text NOT NULL,
  `cta_label` varchar(80) DEFAULT NULL,
  `cta_link` text DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `display_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()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Despejando dados para a tabela `hero_banners`
--

INSERT INTO `hero_banners` (`id`, `title`, `subtitle`, `description`, `image_url`, `cta_label`, `cta_link`, `is_active`, `display_order`, `created_at`, `updated_at`) VALUES
(1, 'GalpÒo Imperial', 'Restaurante ò Bar ò Eventos', 'Almoço, buffet, reservas, música ao vivo e bar completo em Paraju, Domingos Martins.', '/galpao-imperial/ambiente/image.png', 'Fazer reserva', '#menu', 1, 1, '2026-05-29 03:52:20', '2026-05-29 13:27:46');

-- --------------------------------------------------------

--
-- Estrutura para tabela `leisure_activities`
--

CREATE TABLE `leisure_activities` (
  `id` int(11) NOT NULL,
  `title` varchar(180) NOT NULL,
  `activity_date` datetime NOT NULL,
  `time_label` varchar(80) DEFAULT NULL,
  `description` text DEFAULT NULL,
  `image_url` text DEFAULT NULL,
  `accepts_partner` tinyint(1) NOT NULL DEFAULT 1,
  `guest_price` decimal(10,2) DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Despejando dados para a tabela `leisure_activities`
--

INSERT INTO `leisure_activities` (`id`, `title`, `activity_date`, `time_label`, `description`, `image_url`, `accepts_partner`, `guest_price`, `is_active`, `created_at`, `updated_at`) VALUES
(1, 'Domingo de Lazer no Galpão Imperial', '2026-04-26 09:00:00', '09:00h às 17:00h', 'Piscina, churrasco e futebol de sabão para parceiros.', 'https://images.unsplash.com/photo-1519167758481-83f550bb49b3?auto=format&fit=crop&q=80', 1, 30.00, 1, '2026-05-29 03:52:20', '2026-05-29 03:52:20'),
(2, 'Sábado de Piscina e Lazer', '2026-04-25 10:00:00', '10:00h às 16:00h', 'Dia de relaxar na piscina com música ao vivo ambiente.', 'https://images.unsplash.com/photo-1540541338287-41700207dee6?auto=format&fit=crop&q=80', 1, 20.00, 1, '2026-05-29 03:52:20', '2026-05-29 03:52:20');

-- --------------------------------------------------------

--
-- Estrutura para tabela `membership_plans`
--

CREATE TABLE `membership_plans` (
  `id` int(11) NOT NULL,
  `code` varchar(60) NOT NULL,
  `name` varchar(150) NOT NULL,
  `price` decimal(10,2) NOT NULL,
  `validity_days` int(11) NOT NULL DEFAULT 30,
  `benefits_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`benefits_json`)),
  `is_active` tinyint(1) NOT NULL DEFAULT 1,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Despejando dados para a tabela `membership_plans`
--

INSERT INTO `membership_plans` (`id`, `code`, `name`, `price`, `validity_days`, `benefits_json`, `is_active`, `created_at`, `updated_at`) VALUES
(1, 'monthly', 'Parceiro Mensal', 50.00, 30, '[\"Acesso ao espaço em dias permitidos\", \"Piscina e área de banho\", \"Futebol de sabão quando disponível\", \"Churrasco e lazer\", \"Carteirinha digital\", \"Mensalidade acessível\", \"Prioridade em comunicados e eventos\"]', 1, '2026-05-29 03:52:20', '2026-05-29 03:52:20');

-- --------------------------------------------------------

--
-- Estrutura para tabela `orders`
--

CREATE TABLE `orders` (
  `id` int(11) NOT NULL,
  `order_number` varchar(40) NOT NULL,
  `order_type` enum('ticket','membership') NOT NULL DEFAULT 'ticket',
  `event_id` int(11) DEFAULT NULL,
  `partner_id` int(11) DEFAULT NULL,
  `customer_name` varchar(180) NOT NULL,
  `customer_email` varchar(150) DEFAULT NULL,
  `customer_whatsapp` varchar(30) NOT NULL,
  `customer_cpf` varchar(20) DEFAULT NULL,
  `total_value` decimal(10,2) NOT NULL,
  `subtotal_value` decimal(10,2) DEFAULT NULL,
  `platform_fee_value` decimal(10,2) DEFAULT NULL,
  `asaas_fee_value` decimal(10,2) DEFAULT NULL,
  `organizer_net_value` decimal(10,2) DEFAULT NULL,
  `payment_method` enum('pix','credit_card') NOT NULL DEFAULT 'pix',
  `payment_status` enum('pending','paid','cancelled','refunded') NOT NULL DEFAULT 'pending',
  `ticket_status` enum('unused','used','cancelled') DEFAULT 'unused',
  `quantity` int(11) NOT NULL DEFAULT 1,
  `asaas_customer_id` varchar(80) DEFAULT NULL,
  `asaas_payment_id` varchar(80) DEFAULT NULL,
  `asaas_invoice_url` text DEFAULT NULL,
  `external_reference` varchar(120) DEFAULT NULL,
  `raw_response_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`raw_response_json`)),
  `paid_at` datetime DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estrutura para tabela `order_items`
--

CREATE TABLE `order_items` (
  `id` int(11) NOT NULL,
  `order_id` int(11) NOT NULL,
  `batch_id` int(11) DEFAULT NULL,
  `item_name` varchar(180) NOT NULL,
  `unit_price` decimal(10,2) NOT NULL,
  `quantity` int(11) NOT NULL DEFAULT 1,
  `total_price` decimal(10,2) NOT NULL,
  `metadata_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`metadata_json`)),
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estrutura para tabela `partners`
--

CREATE TABLE `partners` (
  `id` int(11) NOT NULL,
  `plan_id` int(11) NOT NULL,
  `full_name` varchar(180) NOT NULL,
  `whatsapp` varchar(30) NOT NULL,
  `cpf` varchar(20) NOT NULL,
  `birth_date` date NOT NULL,
  `email` varchar(150) DEFAULT NULL,
  `photo_url` text DEFAULT NULL,
  `start_date` datetime DEFAULT NULL,
  `expiry_date` datetime DEFAULT NULL,
  `status` enum('active','expired','pending','blocked') NOT NULL DEFAULT 'pending',
  `notes` text DEFAULT NULL,
  `asaas_customer_id` varchar(80) DEFAULT NULL,
  `asaas_payment_id` varchar(80) DEFAULT NULL,
  `last_validated_by` varchar(150) DEFAULT NULL,
  `last_validated_at` datetime DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Despejando dados para a tabela `partners`
--

INSERT INTO `partners` (`id`, `plan_id`, `full_name`, `whatsapp`, `cpf`, `birth_date`, `email`, `photo_url`, `start_date`, `expiry_date`, `status`, `notes`, `asaas_customer_id`, `asaas_payment_id`, `last_validated_by`, `last_validated_at`, `created_at`, `updated_at`) VALUES
(1, 1, 'João da Silva', '27999887766', '123.456.789-00', '1990-05-15', NULL, NULL, '2026-05-29 00:52:20', '2026-06-28 00:52:20', 'active', NULL, NULL, NULL, NULL, NULL, '2026-05-29 03:52:20', '2026-05-29 03:52:20');

-- --------------------------------------------------------

--
-- Estrutura para tabela `site_settings`
--

CREATE TABLE `site_settings` (
  `id` int(11) NOT NULL,
  `site_name` varchar(150) NOT NULL,
  `logo_url` text DEFAULT NULL,
  `whatsapp` varchar(30) NOT NULL,
  `instagram` varchar(100) DEFAULT NULL,
  `contact_email` varchar(150) DEFAULT NULL,
  `address_line` varchar(255) DEFAULT NULL,
  `city` varchar(120) DEFAULT NULL,
  `state_code` char(2) DEFAULT NULL,
  `postal_code` varchar(20) DEFAULT NULL,
  `google_maps_link` text DEFAULT NULL,
  `waze_link` text DEFAULT NULL,
  `pix_key` varchar(255) DEFAULT NULL,
  `organizer_pix_key` varchar(255) DEFAULT NULL,
  `organizer_pix_key_type` varchar(40) NOT NULL DEFAULT 'CPF',
  `organizer_recipient_name` varchar(180) DEFAULT NULL,
  `platform_pix_key` varchar(255) DEFAULT NULL,
  `platform_pix_key_type` varchar(40) NOT NULL DEFAULT 'CPF',
  `platform_recipient_name` varchar(180) DEFAULT NULL,
  `service_tax` decimal(10,2) NOT NULL DEFAULT 0.00,
  `asaas_fee_per_order` decimal(10,2) NOT NULL DEFAULT 0.99,
  `organizer_auto_withdraw_threshold` decimal(10,2) NOT NULL DEFAULT 200.00,
  `organizer_manual_withdraw_fee` decimal(10,2) NOT NULL DEFAULT 0.00,
  `organizer_auto_withdraw_fee` decimal(10,2) NOT NULL DEFAULT 0.00,
  `confirmation_message` text DEFAULT NULL,
  `whatsapp_template` text DEFAULT NULL,
  `asaas_enabled` tinyint(1) NOT NULL DEFAULT 0,
  `asaas_environment` enum('sandbox','production') NOT NULL DEFAULT 'sandbox',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Despejando dados para a tabela `site_settings`
--

INSERT INTO `site_settings` (`id`, `site_name`, `logo_url`, `whatsapp`, `instagram`, `contact_email`, `address_line`, `city`, `state_code`, `postal_code`, `google_maps_link`, `waze_link`, `pix_key`, `organizer_pix_key`, `organizer_pix_key_type`, `organizer_recipient_name`, `platform_pix_key`, `platform_pix_key_type`, `platform_recipient_name`, `service_tax`, `asaas_fee_per_order`, `organizer_auto_withdraw_threshold`, `organizer_manual_withdraw_fee`, `organizer_auto_withdraw_fee`, `confirmation_message`, `whatsapp_template`, `asaas_enabled`, `asaas_environment`, `created_at`, `updated_at`) VALUES
(1, 'Galpão Imperial', '/galpao-imperial/logo/499590839_18021494816651395_7453057703159795787_n.jpg', '(27) 99753-2187', '@galpao.imperial', 'contato@galpaoimperial.com.br', 'R. Tijuco Preto - Paraju', 'Domingos Martins', 'ES', '29273-000', 'https://maps.app.goo.gl/3appdn2QiPPDTPk87', 'https://waze.com/ul?q=Galp%C3%A3o%20Imperial%20Paraju%20Domingos%20Martins%20ES&navigate=yes', '27993411555', NULL, 'CPF', NULL, NULL, 'CPF', NULL, 2.00, 0.99, 200.00, 0.00, 0.00, 'Seu ingresso para o Galpão Imperial foi confirmado!', 'Olá, [nome]. Seu ingresso para [evento] no Galpão Imperial foi confirmado. Código do ingresso: [código].', 0, 'sandbox', '2026-05-29 03:52:20', '2026-05-29 13:27:46');

-- --------------------------------------------------------

--
-- Estrutura para tabela `tickets`
--

CREATE TABLE `tickets` (
  `id` int(11) NOT NULL,
  `order_id` int(11) NOT NULL,
  `order_item_id` int(11) DEFAULT NULL,
  `event_id` int(11) NOT NULL,
  `batch_id` int(11) DEFAULT NULL,
  `ticket_code` varchar(80) NOT NULL,
  `status` enum('unused','used','cancelled') NOT NULL DEFAULT 'unused',
  `validated_by` varchar(150) DEFAULT NULL,
  `validated_at` datetime DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estrutura para tabela `wallet_transactions`
--

CREATE TABLE `wallet_transactions` (
  `id` int(11) NOT NULL,
  `owner_type` enum('organizer','platform') NOT NULL,
  `direction` enum('credit','debit') NOT NULL,
  `amount` decimal(10,2) NOT NULL,
  `category` varchar(80) NOT NULL,
  `description` varchar(255) NOT NULL,
  `reference_type` varchar(60) DEFAULT NULL,
  `reference_id` varchar(120) DEFAULT NULL,
  `metadata_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`metadata_json`)),
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estrutura para tabela `webhook_logs`
--

CREATE TABLE `webhook_logs` (
  `id` int(11) NOT NULL,
  `provider` varchar(40) NOT NULL,
  `event_name` varchar(120) DEFAULT NULL,
  `external_id` varchar(120) DEFAULT NULL,
  `payload_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`payload_json`)),
  `processed` tinyint(1) NOT NULL DEFAULT 0,
  `processing_notes` text DEFAULT NULL,
  `processed_at` datetime DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Estrutura para tabela `withdrawal_requests`
--

CREATE TABLE `withdrawal_requests` (
  `id` int(11) NOT NULL,
  `owner_type` enum('organizer','platform') NOT NULL,
  `trigger_type` enum('manual','auto') NOT NULL DEFAULT 'manual',
  `amount_gross` decimal(10,2) NOT NULL,
  `fee_amount` decimal(10,2) NOT NULL DEFAULT 0.00,
  `amount_net` decimal(10,2) NOT NULL,
  `destination_pix_key` varchar(255) NOT NULL,
  `destination_pix_key_type` varchar(40) NOT NULL,
  `destination_name` varchar(180) DEFAULT NULL,
  `requested_by` varchar(120) DEFAULT NULL,
  `approved_with_key` tinyint(1) NOT NULL DEFAULT 0,
  `status` enum('pending','completed','failed') NOT NULL DEFAULT 'pending',
  `asaas_transfer_id` varchar(80) DEFAULT NULL,
  `asaas_response_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`asaas_response_json`)),
  `error_message` text DEFAULT NULL,
  `metadata_json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`metadata_json`)),
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `processed_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Índices de tabela `events`
--
ALTER TABLE `events`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `slug` (`slug`);

--
-- Índices de tabela `event_batches`
--
ALTER TABLE `event_batches`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_event_batches_event` (`event_id`);

--
-- Índices de tabela `gallery_images`
--
ALTER TABLE `gallery_images`
  ADD PRIMARY KEY (`id`);

--
-- Índices de tabela `gift_claims`
--
ALTER TABLE `gift_claims`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `claim_code` (`claim_code`),
  ADD KEY `idx_gift_claims_lookup` (`claim_code`,`whatsapp`,`cpf`,`status`);

--
-- Índices de tabela `hero_banners`
--
ALTER TABLE `hero_banners`
  ADD PRIMARY KEY (`id`);

--
-- Índices de tabela `leisure_activities`
--
ALTER TABLE `leisure_activities`
  ADD PRIMARY KEY (`id`);

--
-- Índices de tabela `membership_plans`
--
ALTER TABLE `membership_plans`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `code` (`code`);

--
-- Índices de tabela `orders`
--
ALTER TABLE `orders`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `order_number` (`order_number`),
  ADD KEY `fk_orders_event` (`event_id`),
  ADD KEY `fk_orders_partner` (`partner_id`),
  ADD KEY `idx_orders_payment_status` (`payment_status`,`created_at`),
  ADD KEY `idx_orders_customer_cpf` (`customer_cpf`),
  ADD KEY `idx_orders_payment_id` (`asaas_payment_id`);

--
-- Índices de tabela `order_items`
--
ALTER TABLE `order_items`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_order_items_order` (`order_id`),
  ADD KEY `fk_order_items_batch` (`batch_id`);

--
-- Índices de tabela `partners`
--
ALTER TABLE `partners`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_partners_plan` (`plan_id`);

--
-- Índices de tabela `site_settings`
--
ALTER TABLE `site_settings`
  ADD PRIMARY KEY (`id`);

--
-- Índices de tabela `tickets`
--
ALTER TABLE `tickets`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `ticket_code` (`ticket_code`),
  ADD KEY `fk_tickets_order` (`order_id`),
  ADD KEY `fk_tickets_order_item` (`order_item_id`),
  ADD KEY `fk_tickets_event` (`event_id`),
  ADD KEY `fk_tickets_batch` (`batch_id`),
  ADD KEY `idx_tickets_code_status` (`ticket_code`,`status`);

--
-- Índices de tabela `wallet_transactions`
--
ALTER TABLE `wallet_transactions`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_wallet_owner_created` (`owner_type`,`created_at`),
  ADD KEY `idx_wallet_reference` (`reference_type`,`reference_id`);

--
-- Índices de tabela `webhook_logs`
--
ALTER TABLE `webhook_logs`
  ADD PRIMARY KEY (`id`);

--
-- Índices de tabela `withdrawal_requests`
--
ALTER TABLE `withdrawal_requests`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_withdraw_owner_status` (`owner_type`,`status`,`created_at`);

--
-- AUTO_INCREMENT de tabela `events`
--
ALTER TABLE `events`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;

--
-- AUTO_INCREMENT de tabela `event_batches`
--
ALTER TABLE `event_batches`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;

--
-- AUTO_INCREMENT de tabela `gallery_images`
--
ALTER TABLE `gallery_images`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=15;

--
-- AUTO_INCREMENT de tabela `gift_claims`
--
ALTER TABLE `gift_claims`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT de tabela `hero_banners`
--
ALTER TABLE `hero_banners`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT de tabela `leisure_activities`
--
ALTER TABLE `leisure_activities`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT de tabela `membership_plans`
--
ALTER TABLE `membership_plans`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT de tabela `orders`
--
ALTER TABLE `orders`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de tabela `order_items`
--
ALTER TABLE `order_items`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de tabela `partners`
--
ALTER TABLE `partners`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT de tabela `site_settings`
--
ALTER TABLE `site_settings`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT de tabela `tickets`
--
ALTER TABLE `tickets`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de tabela `wallet_transactions`
--
ALTER TABLE `wallet_transactions`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de tabela `webhook_logs`
--
ALTER TABLE `webhook_logs`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT de tabela `withdrawal_requests`
--
ALTER TABLE `withdrawal_requests`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- Restrições para tabelas despejadas
--

--
-- Restrições para tabelas `event_batches`
--
ALTER TABLE `event_batches`
  ADD CONSTRAINT `fk_event_batches_event` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE CASCADE;

--
-- Restrições para tabelas `orders`
--
ALTER TABLE `orders`
  ADD CONSTRAINT `fk_orders_event` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `fk_orders_partner` FOREIGN KEY (`partner_id`) REFERENCES `partners` (`id`) ON DELETE SET NULL;

--
-- Restrições para tabelas `order_items`
--
ALTER TABLE `order_items`
  ADD CONSTRAINT `fk_order_items_batch` FOREIGN KEY (`batch_id`) REFERENCES `event_batches` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `fk_order_items_order` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE;

--
-- Restrições para tabelas `partners`
--
ALTER TABLE `partners`
  ADD CONSTRAINT `fk_partners_plan` FOREIGN KEY (`plan_id`) REFERENCES `membership_plans` (`id`);

--
-- Restrições para tabelas `tickets`
--
ALTER TABLE `tickets`
  ADD CONSTRAINT `fk_tickets_batch` FOREIGN KEY (`batch_id`) REFERENCES `event_batches` (`id`) ON DELETE SET NULL,
  ADD CONSTRAINT `fk_tickets_event` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_tickets_order` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_tickets_order_item` FOREIGN KEY (`order_item_id`) REFERENCES `order_items` (`id`) ON DELETE SET NULL;
COMMIT;

