CREATE TABLE `active_connections` (
	`id` int AUTO_INCREMENT NOT NULL,
	`userId` int NOT NULL,
	`sessionToken` varchar(255) NOT NULL,
	`ipAddress` varchar(45),
	`userAgent` text,
	`connectedAt` timestamp NOT NULL DEFAULT (now()),
	`lastActivityAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `active_connections_id` PRIMARY KEY(`id`),
	CONSTRAINT `active_connections_sessionToken_unique` UNIQUE(`sessionToken`)
);
--> statement-breakpoint
CREATE TABLE `music_tracks` (
	`id` int AUTO_INCREMENT NOT NULL,
	`categoryId` int NOT NULL,
	`title` varchar(255) NOT NULL,
	`artist` varchar(255),
	`album` varchar(255),
	`duration` int,
	`streamUrl` text NOT NULL,
	`thumbnailUrl` text,
	`isActive` boolean NOT NULL DEFAULT true,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `music_tracks_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `stream_categories` (
	`id` int AUTO_INCREMENT NOT NULL,
	`name` varchar(255) NOT NULL,
	`description` text,
	`categoryType` enum('live','vod','series','music') NOT NULL DEFAULT 'music',
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	CONSTRAINT `stream_categories_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `xtream_users` (
	`id` int AUTO_INCREMENT NOT NULL,
	`username` varchar(255) NOT NULL,
	`password` varchar(255) NOT NULL,
	`expirationDate` timestamp,
	`maxConnections` int NOT NULL DEFAULT 1,
	`isActive` boolean NOT NULL DEFAULT true,
	`createdAt` timestamp NOT NULL DEFAULT (now()),
	`updatedAt` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `xtream_users_id` PRIMARY KEY(`id`),
	CONSTRAINT `xtream_users_username_unique` UNIQUE(`username`)
);
--> statement-breakpoint
CREATE INDEX `userId_idx` ON `active_connections` (`userId`);--> statement-breakpoint
CREATE INDEX `sessionToken_idx` ON `active_connections` (`sessionToken`);--> statement-breakpoint
CREATE INDEX `categoryId_idx` ON `music_tracks` (`categoryId`);--> statement-breakpoint
CREATE INDEX `username_idx` ON `xtream_users` (`username`);