CREATE TABLE `musica_albuns` (
	`id` int AUTO_INCREMENT NOT NULL,
	`titulo` varchar(255) NOT NULL,
	`slug` varchar(255),
	`descricao` text,
	`capa` varchar(500),
	`ano_lancamento` int,
	`genero` varchar(100),
	`artista_id` int,
	`status` enum('rascunho','publicado','arquivado') DEFAULT 'publicado',
	`ativo` int DEFAULT 1,
	`criado_em` timestamp DEFAULT (now()),
	`atualizado_em` timestamp DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `musica_albuns_id` PRIMARY KEY(`id`),
	CONSTRAINT `musica_albuns_slug_unique` UNIQUE(`slug`)
);
--> statement-breakpoint
CREATE TABLE `musica_artistas` (
	`id` int AUTO_INCREMENT NOT NULL,
	`nome` varchar(255) NOT NULL,
	`slug` varchar(255),
	`bio` text,
	`foto` varchar(500),
	`reproducoes` int DEFAULT 0,
	`ativo` int DEFAULT 1,
	`criado_em` timestamp DEFAULT (now()),
	`atualizado_em` timestamp DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `musica_artistas_id` PRIMARY KEY(`id`),
	CONSTRAINT `musica_artistas_slug_unique` UNIQUE(`slug`)
);
--> statement-breakpoint
CREATE TABLE `musica_faixas` (
	`id` int AUTO_INCREMENT NOT NULL,
	`titulo` varchar(255) NOT NULL,
	`slug` varchar(255),
	`descricao` text,
	`arquivo` varchar(500),
	`tipo_midia` enum('audio','video','audio_video') NOT NULL DEFAULT 'audio',
	`video_url` varchar(500),
	`capa` varchar(500),
	`duracao` int,
	`reproducoes` int DEFAULT 0,
	`numero_faixa` int,
	`ordem` int DEFAULT 0,
	`letra` text,
	`tags` text,
	`artista_id` int,
	`album_id` int,
	`status` enum('rascunho','publicado','agendado') DEFAULT 'publicado',
	`data_publicacao` timestamp DEFAULT (now()),
	`ativo` int DEFAULT 1,
	`criado_em` timestamp DEFAULT (now()),
	`atualizado_em` timestamp DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `musica_faixas_id` PRIMARY KEY(`id`),
	CONSTRAINT `musica_faixas_slug_unique` UNIQUE(`slug`)
);
--> statement-breakpoint
CREATE TABLE `podcast_vinhetas` (
	`id` int AUTO_INCREMENT NOT NULL,
	`titulo` varchar(255) NOT NULL,
	`arquivo` varchar(500) NOT NULL,
	`categoria` enum('abertura','transicao','encerramento') DEFAULT 'transicao',
	`ativo` tinyint DEFAULT 1,
	`criado_em` timestamp DEFAULT (now()),
	CONSTRAINT `podcast_vinhetas_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `user_favoritos_musica` (
	`id` int AUTO_INCREMENT NOT NULL,
	`user_id` int NOT NULL,
	`faixa_id` int NOT NULL,
	`criado_em` timestamp DEFAULT (now()),
	CONSTRAINT `user_favoritos_musica_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `user_historico_musica` (
	`id` int AUTO_INCREMENT NOT NULL,
	`user_id` int NOT NULL,
	`faixa_id` int NOT NULL,
	`tocado_em` timestamp DEFAULT (now()),
	CONSTRAINT `user_historico_musica_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `user_playlist_items_musica` (
	`id` int AUTO_INCREMENT NOT NULL,
	`playlist_id` int NOT NULL,
	`faixa_id` int NOT NULL,
	`ordem` int DEFAULT 0,
	`adicionado_em` timestamp DEFAULT (now()),
	CONSTRAINT `user_playlist_items_musica_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
ALTER TABLE `users` MODIFY COLUMN `name` varchar(255);--> statement-breakpoint
ALTER TABLE `users` MODIFY COLUMN `loginMethod` varchar(64) DEFAULT 'local';--> statement-breakpoint
ALTER TABLE `users` MODIFY COLUMN `role` enum('user','admin','editor','operator','analyst') NOT NULL DEFAULT 'user';--> statement-breakpoint
ALTER TABLE `podcast_episodios` ADD `slug` varchar(255);--> statement-breakpoint
ALTER TABLE `podcast_episodios` ADD `tipo_midia` enum('audio','video','audio_video') DEFAULT 'audio' NOT NULL;--> statement-breakpoint
ALTER TABLE `podcast_episodios` ADD `video_url` varchar(500);--> statement-breakpoint
ALTER TABLE `podcast_episodios` ADD `ordem` int DEFAULT 0;--> statement-breakpoint
ALTER TABLE `podcast_episodios` ADD `transcricao` text;--> statement-breakpoint
ALTER TABLE `podcast_episodios` ADD `status` enum('rascunho','publicado','agendado') DEFAULT 'publicado';--> statement-breakpoint
ALTER TABLE `podcast_episodios` ADD `data_publicacao` timestamp DEFAULT (now());--> statement-breakpoint
ALTER TABLE `podcast_programas` ADD `categoria` varchar(100) DEFAULT 'podcast';--> statement-breakpoint
ALTER TABLE `podcast_programas` ADD `status` enum('rascunho','publicado','arquivado') DEFAULT 'publicado';--> statement-breakpoint
ALTER TABLE `podcast_programas` ADD `config_autodj` tinyint DEFAULT 1;--> statement-breakpoint
ALTER TABLE `podcast_programas` ADD `config_sequencial` tinyint DEFAULT 1;--> statement-breakpoint
ALTER TABLE `podcast_programas` ADD `config_vinheta` tinyint DEFAULT 0;--> statement-breakpoint
ALTER TABLE `user_playlists` ADD `capa` varchar(500);--> statement-breakpoint
ALTER TABLE `users` ADD `password` varchar(255);--> statement-breakpoint
ALTER TABLE `podcast_apresentadores` ADD CONSTRAINT `podcast_apresentadores_slug_unique` UNIQUE(`slug`);--> statement-breakpoint
ALTER TABLE `podcast_episodios` ADD CONSTRAINT `podcast_episodios_slug_unique` UNIQUE(`slug`);--> statement-breakpoint
ALTER TABLE `podcast_programas` ADD CONSTRAINT `podcast_programas_slug_unique` UNIQUE(`slug`);--> statement-breakpoint
ALTER TABLE `users` ADD CONSTRAINT `users_email_unique` UNIQUE(`email`);