<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `hr_departments` (
            `id`                    BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `parent_id`             BIGINT UNSIGNED NULL,
            `department_code`       VARCHAR(20) NOT NULL,
            `name_ar`               VARCHAR(200) NOT NULL,
            `name_en`               VARCHAR(200) NULL,
            `description_ar`        TEXT NULL,
            `manager_employee_id`   BIGINT UNSIGNED NULL,
            `branch_id`             BIGINT UNSIGNED NULL,
            `is_active`             TINYINT(1) NOT NULL DEFAULT 1,
            `sort_order`            INT UNSIGNED NOT NULL DEFAULT 0,
            `created_at`            TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at`            TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            `created_by`            BIGINT UNSIGNED NULL,
            `updated_by`            BIGINT UNSIGNED NULL,
            `is_archived`           TINYINT(1) NOT NULL DEFAULT 0,
            `archived_at`           TIMESTAMP NULL DEFAULT NULL,
            `archived_by`           BIGINT UNSIGNED NULL,
            UNIQUE KEY `uq_hr_departments_code` (`department_code`),
            INDEX `idx_hr_departments_parent` (`parent_id`),
            INDEX `idx_hr_departments_branch` (`branch_id`),
            INDEX `idx_hr_departments_active` (`is_active`),
            INDEX `idx_hr_departments_archived` (`is_archived`),
            CONSTRAINT `fk_hr_departments_parent` FOREIGN KEY (`parent_id`) REFERENCES `hr_departments`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_hr_departments_manager` FOREIGN KEY (`manager_employee_id`) REFERENCES `employees`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_hr_departments_branch` FOREIGN KEY (`branch_id`) REFERENCES `branches`(`id`) ON DELETE SET NULL
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `hr_departments`",
];
