-- Initial MVP slice for the OKR SaaS thin workflow.
CREATE TABLE IF NOT EXISTS okr_items (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    organization_name VARCHAR(120) NOT NULL,
    organization_slug VARCHAR(120) NOT NULL,
    owner_name VARCHAR(120) NOT NULL,
    owner_email VARCHAR(160) NOT NULL,
    owner_role VARCHAR(40) NOT NULL,
    department_name VARCHAR(120) NOT NULL,
    period_name VARCHAR(120) NOT NULL,
    objective_title VARCHAR(255) NOT NULL,
    key_result_title VARCHAR(255) NOT NULL,
    description TEXT NULL,
    target_value DECIMAL(10,2) NOT NULL DEFAULT 100.00,
    current_value DECIMAL(10,2) NOT NULL DEFAULT 0.00,
    score_percent DECIMAL(5,2) NOT NULL DEFAULT 0.00,
    status VARCHAR(40) NOT NULL DEFAULT 'draft',
    approval_state VARCHAR(40) NOT NULL DEFAULT 'pending_manager',
    manager_comment TEXT NULL,
    created_by_email VARCHAR(160) NOT NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    INDEX idx_scope (organization_slug, department_name, approval_state),
    INDEX idx_owner (owner_email, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
