-- CreateTable
CREATE TABLE `loan_applications` (
    `id` VARCHAR(191) NOT NULL,
    `user_id` VARCHAR(191) NOT NULL,
    `application_number` VARCHAR(20) NOT NULL,
    `loan_amount` DECIMAL(12, 2) NOT NULL,
    `status` ENUM('PENDING_REVIEW', 'ACCEPTED', 'REJECTED', 'CANCELLED') NOT NULL DEFAULT 'PENDING_REVIEW',
    `applicant_name` VARCHAR(120) NOT NULL,
    `applicant_phone` VARCHAR(15) NULL,
    `applicant_email` VARCHAR(120) NOT NULL,
    `applicant_city` VARCHAR(80) NULL,
    `applicant_state` VARCHAR(80) NULL,
    `applicant_country` VARCHAR(80) NULL,
    `applicant_address` VARCHAR(500) NULL,
    `applicant_pincode` VARCHAR(10) NULL,
    `applicant_gender` ENUM('MALE', 'FEMALE', 'OTHER', 'PREFER_NOT_TO_SAY') NULL,
    `applicant_date_of_birth` DATE NULL,
    `applicant_alternate_phone` VARCHAR(15) NULL,
    `applicant_image_url` VARCHAR(500) NULL,
    `admin_note` VARCHAR(500) NULL,
    `updated_by_user_id` VARCHAR(191) NULL,
    `updated_by_name` VARCHAR(120) NULL,
    `updated_by_role` ENUM('USER', 'DEALER', 'EMPLOYEE', 'SUPERADMIN') NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,

    UNIQUE INDEX `loan_applications_application_number_key`(`application_number`),
    INDEX `loan_applications_user_id_created_at_idx`(`user_id`, `created_at`),
    INDEX `loan_applications_status_created_at_idx`(`status`, `created_at`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `loan_applications` ADD CONSTRAINT `loan_applications_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
