-- Pack 22.1 – Statuses + Persistent Project Menu + Bilingual Core + Admin Invite Users

CREATE TABLE IF NOT EXISTS user_invites (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT,
    email VARCHAR(190) NOT NULL,
    role VARCHAR(50) NOT NULL,
    employee_id INT UNSIGNED NULL,
    external_partner_id INT UNSIGNED NULL,
    customer_id INT UNSIGNED NULL,
    invite_token VARCHAR(120) NOT NULL,
    invited_by_user_id INT UNSIGNED NULL,
    is_used TINYINT(1) NOT NULL DEFAULT 0,
    expires_at DATETIME NOT NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (id),
    UNIQUE KEY uq_user_invites_token (invite_token),
    KEY idx_user_invites_email (email),
    KEY idx_user_invites_used (is_used)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO settings (setting_key, setting_value)
VALUES
('app_language', 'el'),
('invite_email_from_name', 'GoPools CRM'),
('invite_email_subject_el', 'Πρόσκληση πρόσβασης στο GoPools CRM'),
('invite_email_subject_en', 'Invitation to access GoPools CRM')
ON DUPLICATE KEY UPDATE setting_value = VALUES(setting_value);
