-- Users of the platform (dashboard/admin accounts). Not to be confused with
-- the anonymous visitors being verified.
CREATE TABLE IF NOT EXISTS `users` (
    `id`         BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    `name`       VARCHAR(120)    NOT NULL,
    `email`      VARCHAR(190)    NOT NULL,
    `password`   VARCHAR(255)    NOT NULL,
    `role`       ENUM('admin','user') NOT NULL DEFAULT 'user',
    `status`     ENUM('active','suspended') NOT NULL DEFAULT 'active',
    `api_key`    CHAR(64)        NULL,
    `company`    VARCHAR(160)    NULL,
    `last_login_at` DATETIME     NULL,
    `created_at` DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at` DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    UNIQUE KEY `uq_users_email` (`email`),
    UNIQUE KEY `uq_users_api_key` (`api_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
