<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `cost_centers` (
            `id`              BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `code`            VARCHAR(20)     NOT NULL,
            `name_ar`         VARCHAR(150)    NOT NULL,
            `name_en`         VARCHAR(150)    NOT NULL,
            `type`            ENUM('cost_center','profit_center') NOT NULL DEFAULT 'cost_center',
            `branch_id`       BIGINT UNSIGNED NULL COMMENT 'Linked branch for branch-based accounting',
            `parent_id`       BIGINT UNSIGNED NULL,
            `is_active`       TINYINT(1)      NOT NULL DEFAULT 1,
            `description`     TEXT            NULL,
            `is_archived`     TINYINT(1)      NOT NULL DEFAULT 0,
            `archived_at`     DATETIME        NULL,
            `archived_by`     BIGINT UNSIGNED NULL,
            `created_at`      DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at`      DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            `created_by`      BIGINT UNSIGNED NULL,
            `updated_by`      BIGINT UNSIGNED NULL,

            UNIQUE INDEX `idx_cc_code`        (`code`),
            INDEX `idx_cc_branch_id`           (`branch_id`),
            INDEX `idx_cc_parent_id`           (`parent_id`),
            INDEX `idx_cc_type`                (`type`),
            CONSTRAINT `fk_cc_branch`     FOREIGN KEY (`branch_id`)  REFERENCES `branches`(`id`),
            CONSTRAINT `fk_cc_parent`     FOREIGN KEY (`parent_id`)  REFERENCES `cost_centers`(`id`),
            CONSTRAINT `fk_cc_created_by` FOREIGN KEY (`created_by`) REFERENCES `employees`(`id`),
            CONSTRAINT `fk_cc_updated_by` FOREIGN KEY (`updated_by`) REFERENCES `employees`(`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `cost_centers`",
];
