-- --------------------------------------------------------
-- Baza danych: `czat`
-- --------------------------------------------------------
CREATE DATABASE IF NOT EXISTS `czat` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE `czat`;

-- Tabela użytkowników
CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `gg` bigint(20) NOT NULL,
  `nick` varchar(50) NOT NULL,
  `online` tinyint(1) DEFAULT '0',
  `staff` tinyint(2) DEFAULT '0',
  `rejestracja` int(11) NOT NULL,
  `password` varchar(255) DEFAULT NULL,
  `description` text DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `gg` (`gg`),
  KEY `online` (`online`),
  KEY `staff` (`staff`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Tabela banów
CREATE TABLE IF NOT EXISTS `bans` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `gg` bigint(20) NOT NULL,
  `reason` text DEFAULT NULL,
  `time` int(11) NOT NULL,
  `active` tinyint(1) DEFAULT '1',
  PRIMARY KEY (`id`),
  KEY `gg` (`gg`),
  KEY `active` (`active`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Tabela komend
CREATE TABLE IF NOT EXISTS `cmd` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `cmd` varchar(50) NOT NULL,
  `alias` varchar(50) DEFAULT NULL,
  `staff` tinyint(2) DEFAULT '0',
  PRIMARY KEY (`id`),
  UNIQUE KEY `cmd` (`cmd`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Tabela logów administracyjnych
CREATE TABLE IF NOT EXISTS `logs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `gg` bigint(20) NOT NULL,
  `action` varchar(255) NOT NULL,
  `details` text DEFAULT NULL,
  `timestamp` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `gg` (`gg`),
  KEY `timestamp` (`timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Tabela logów czatu
CREATE TABLE IF NOT EXISTS `chat_logs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `gg` bigint(20) NOT NULL,
  `nick` varchar(50) NOT NULL,
  `message` text NOT NULL,
  `timestamp` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `gg` (`gg`),
  KEY `timestamp` (`timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Tabela statusu bota (jeden rekord)
CREATE TABLE IF NOT EXISTS `bot_status` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `status` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Wypełnienie domyślnym statusem
INSERT INTO `bot_status` (`id`, `status`) VALUES (1, 'Serdecznie zapraszamy dołącz do nas wpisując /join miłej rozmowy:)')
ON DUPLICATE KEY UPDATE `status` = VALUES(`status`);