<?php
declare(strict_types=1);

return [
    'up' => "
        CREATE TABLE IF NOT EXISTS `members` (
            `id`                     BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            `membership_number`      VARCHAR(20) NULL,
            `form_number`            VARCHAR(50) NULL,
            `form_date`              DATE NULL,
            `form_submission_id`     BIGINT UNSIGNED NULL,
            `branch_id`              BIGINT UNSIGNED NOT NULL,
            `membership_type`        VARCHAR(50) NOT NULL DEFAULT 'working',
            `member_category`        VARCHAR(50) NOT NULL DEFAULT 'working_member',
            `status`                 VARCHAR(50) NOT NULL DEFAULT 'potential',
            `full_name_ar`           VARCHAR(200) NOT NULL,
            `full_name_en`           VARCHAR(200) NULL,
            `national_id`            VARCHAR(14) NULL,
            `passport_number`        VARCHAR(50) NULL,
            `id_type`                VARCHAR(20) NOT NULL DEFAULT 'national_id',
            `id_issue_date`          DATE NULL,
            `id_expiry_date`         DATE NULL,
            `date_of_birth`          DATE NOT NULL,
            `age_years`              INT UNSIGNED NULL,
            `age_months`             INT UNSIGNED NULL,
            `gender`                 VARCHAR(10) NOT NULL,
            `place_of_birth`         VARCHAR(200) NULL,
            `nationality`            VARCHAR(100) NULL DEFAULT 'مصري',
            `governorate_code`       VARCHAR(2) NULL,
            `religion`               VARCHAR(50) NULL,
            `qualification_id`       BIGINT UNSIGNED NULL,
            `marital_status`         VARCHAR(30) NULL,
            `phone_home`             VARCHAR(20) NULL,
            `phone_mobile`           VARCHAR(20) NOT NULL,
            `phone_international`    VARCHAR(30) NULL,
            `email`                  VARCHAR(255) NULL,
            `emergency_name`         VARCHAR(200) NULL,
            `emergency_phone`        VARCHAR(20) NULL,
            `residence_type`         VARCHAR(30) NULL,
            `residence_address`      TEXT NULL,
            `landmark`               VARCHAR(200) NULL,
            `floor`                  VARCHAR(20) NULL,
            `apartment`              VARCHAR(20) NULL,
            `area`                   VARCHAR(100) NULL,
            `governorate`            VARCHAR(100) NULL,
            `correspondence_address` VARCHAR(50) NULL,
            `employment_type`        VARCHAR(50) NULL,
            `occupation`             VARCHAR(200) NULL,
            `job_title`              VARCHAR(200) NULL,
            `employment_date`        DATE NULL,
            `business_address`       TEXT NULL,
            `office_phone`           VARCHAR(20) NULL,
            `office_fax`             VARCHAR(20) NULL,
            `business_activity`      VARCHAR(200) NULL,
            `membership_value`       DECIMAL(15,2) NULL,
            `payment_method`         VARCHAR(30) NULL,
            `referral_source`        VARCHAR(100) NULL,
            `photo_path`             VARCHAR(500) NULL,
            `workflow_instance_id`   BIGINT UNSIGNED NULL,
            `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_members_membership_number` (`membership_number`),
            UNIQUE KEY `uq_members_national_id` (`national_id`),
            INDEX `idx_members_branch` (`branch_id`),
            INDEX `idx_members_status` (`status`),
            INDEX `idx_members_type` (`membership_type`),
            INDEX `idx_members_name_ar` (`full_name_ar`),
            INDEX `idx_members_phone` (`phone_mobile`),
            INDEX `idx_members_passport` (`passport_number`),
            INDEX `idx_members_form` (`form_number`),
            INDEX `idx_members_archived` (`is_archived`),
            INDEX `idx_members_qualification` (`qualification_id`),
            INDEX `idx_members_workflow` (`workflow_instance_id`),
            CONSTRAINT `fk_members_branch` FOREIGN KEY (`branch_id`) REFERENCES `branches`(`id`),
            CONSTRAINT `fk_members_qualification` FOREIGN KEY (`qualification_id`) REFERENCES `qualifications`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_members_form_sub` FOREIGN KEY (`form_submission_id`) REFERENCES `form_submissions`(`id`) ON DELETE SET NULL,
            CONSTRAINT `fk_members_workflow` FOREIGN KEY (`workflow_instance_id`) REFERENCES `workflow_instances`(`id`) ON DELETE SET NULL
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
    ",
    'down' => "DROP TABLE IF EXISTS `members`",
];