/* 
   Bu SQL komutlarını phpMyAdmin üzerinden 'restapi' isimli 
   YENİ veritabanına tıklayıp "SQL" sekmesinden çalıştırın. 
*/

CREATE TABLE IF NOT EXISTS `matches` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `external_id` varchar(255) DEFAULT NULL,
  `home_team` varchar(255) DEFAULT NULL,
  `away_team` varchar(255) DEFAULT NULL,
  `league` varchar(255) DEFAULT NULL,
  `match_date` date DEFAULT NULL,
  `match_time` time DEFAULT NULL,
  `home_team_logo` varchar(255) DEFAULT NULL,
  `away_team_logo` varchar(255) DEFAULT NULL,
  `stream_url` text DEFAULT NULL,
  `views` int(11) DEFAULT 0,
  `status` enum('live','upcoming','finished') DEFAULT 'upcoming',
  `is_active` tinyint(1) DEFAULT 1,
  `sport_id` int(11) DEFAULT 1,
  `channel_id` int(11) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `external_id` (`external_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `channels` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `logo` varchar(255) DEFAULT NULL,
  `stream_url` text DEFAULT NULL,
  `category` varchar(50) DEFAULT 'general',
  `status` enum('active','inactive') DEFAULT 'active',
  `sort_order` int(11) DEFAULT 0,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `sports` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  `slug` varchar(100) NOT NULL,
  `icon` varchar(255) DEFAULT NULL,
  `status` enum('active','inactive') DEFAULT 'active',
  `sort_order` int(11) DEFAULT 0,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO `sports` (`id`, `name`, `slug`, `icon`, `status`, `sort_order`) VALUES
(1, 'Futbol', 'football', 'fas fa-futbol', 'active', 1),
(2, 'Basketbol', 'basketball', 'fas fa-basketball-ball', 'active', 2),
(3, 'Tenis', 'tennis', 'fas fa-table-tennis', 'active', 3),
(4, 'Voleybol', 'volleyball', 'fas fa-volleyball-ball', 'active', 4);
