-- Multi-Tenant Music Submission Database Schema

-- Create database
CREATE DATABASE IF NOT EXISTS `music_submission_api` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE `music_submission_api`;

-- Tenants table
CREATE TABLE `tenants` (
  `tenant_id` CHAR(36) NOT NULL DEFAULT (UUID()),
  `name` VARCHAR(255) NOT NULL,
  `slug` VARCHAR(255) UNIQUE NOT NULL,
  `plan_id` INT DEFAULT 1,
  `timezone` VARCHAR(50) DEFAULT 'UTC',
  `locale` VARCHAR(10) DEFAULT 'en-US',
  `currency` VARCHAR(10) DEFAULT 'USD',
  `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
  `status` ENUM('active','suspended','deleted') DEFAULT 'active',
  `metadata` JSON DEFAULT NULL,
  PRIMARY KEY (`tenant_id`),
  KEY `slug` (`slug`),
  KEY `status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- ... (include all other table definitions from previous implementation)


-- Insert sample data
INSERT INTO `tenants` (`tenant_id`, `name`, `slug`, `plan_id`, `timezone`, `locale`, `currency`) VALUES
(UUID(), 'Global Music Distributors', 'global-music', 2, 'America/New_York', 'en-US', 'USD'),
(UUID(), 'Urban Beats Records', 'urban-beats', 1, 'UTC', 'en-US', 'USD');

-- Insert default features
INSERT INTO `features` (`feature_key`, `description`, `default_enabled`) VALUES
('priority_distribution', 'Expedited delivery to DSPs', 0),
('advanced_analytics', 'Detailed streaming analytics', 1),
('api_access', 'API access for developers', 1);
