ALTER TABLE `company` ADD `notification_settings` TEXT NOT NULL AFTER `totem_settings`;

ALTER TABLE `notification` CHANGE `date_created` `date_created` DATETIME NOT NULL;
ALTER TABLE `notification` ADD `data` TEXT NOT NULL AFTER `message`;

CREATE TABLE `notification_scheduled` (
    `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    `company_id` INT(11) NOT NULL,
    `title` VARCHAR(50) NOT NULL,
    `message` TEXT NOT NULL,
    `notification_option` JSON NOT NULL,
    `type` TINYINT UNSIGNED NOT NULL COMMENT '0 = últimos clientes, 1 = entre datas, 2 = mais ativos, 3 = especifico, 4 = todos',
    `customers_quantity` INT UNSIGNED DEFAULT NULL,
    `customer_identifier_id` INT UNSIGNED DEFAULT NULL,
    `start_date` DATETIME DEFAULT NULL,
    `end_date` DATETIME DEFAULT NULL,
    
    `recurring` BOOLEAN NOT NULL DEFAULT FALSE,
    `recurring_day` TINYINT UNSIGNED DEFAULT NULL COMMENT '1 a 31 (dia fixo do mês)',
    `recurring_weekday` ENUM('monday','tuesday','wednesday','thursday','friday','saturday','sunday') DEFAULT NULL,
    `recurring_time` TIME DEFAULT NULL,
    
    `schedule_date` DATETIME DEFAULT NULL COMMENT 'Para notificações não recorrentes',
    
    `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at` DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

ALTER TABLE `cart` ADD `code` VARCHAR(15) NOT NULL AFTER `company_id`;

ALTER TABLE `company` ADD `seo_settings` TEXT NOT NULL AFTER `notification_settings`;

ALTER TABLE `company` ADD `switch_print_group_items` TINYINT NOT NULL AFTER `switch_print_resume`;

ALTER TABLE `web_setting` ADD `firebase_google_services_android` VARCHAR(100) NOT NULL AFTER `fcm_service_account_file`, ADD `firebase_service_account_android` VARCHAR(100) NOT NULL AFTER `firebase_google_services_android`;

ALTER TABLE `cron_notify` ADD `fcm_token_android` VARCHAR(255) NULL DEFAULT NULL AFTER `fcm_token`;

CREATE TABLE `fcm_tokens` (
    `id` BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    `token_android` VARCHAR(255) NOT NULL,
    `phone_number` VARCHAR(20) NOT NULL,
    `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at` DATETIME NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
