-- Add TxAdmin tables to nbrp_aegis database

-- TxAdmin Server Configuration table
CREATE TABLE IF NOT EXISTS `txadmin_server_config` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `serverUrl` VARCHAR(255) NOT NULL,
  `isActive` BOOLEAN NOT NULL DEFAULT TRUE,
  `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
  `updatedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  PRIMARY KEY (`id`),
  INDEX `txadmin_server_config_isActive_idx` (`isActive`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- TxAdmin User Configuration table
CREATE TABLE IF NOT EXISTS `txadmin_user_config` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `userId` INT NOT NULL,
  `username` VARCHAR(100) NOT NULL,
  `password` VARCHAR(255) NOT NULL,
  `isActive` BOOLEAN NOT NULL DEFAULT TRUE,
  `isLoggedIn` BOOLEAN NOT NULL DEFAULT FALSE,
  `lastLogin` DATETIME(3) NULL,
  `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
  `updatedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  PRIMARY KEY (`id`),
  INDEX `txadmin_user_config_userId_idx` (`userId`),
  INDEX `txadmin_user_config_isActive_idx` (`isActive`),
  FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
