<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        App\Support\SqliteCompat::statement(<<<'SQL'
CREATE TABLE `communication_logs` (
`id` int UNSIGNED NOT NULL,
  `student_id` int UNSIGNED NOT NULL,
  `family_id` int UNSIGNED NOT NULL,
  `student_name` varchar(255) DEFAULT NULL,
  `template_key` varchar(100) DEFAULT NULL,
  `subject` varchar(255) DEFAULT NULL,
  `body` mediumtext DEFAULT NULL,
  `recipients` text DEFAULT NULL,
  `cc` text DEFAULT NULL,
  `bcc` text DEFAULT NULL,
  `attachments` text DEFAULT NULL,
  `status` varchar(32) DEFAULT NULL,
  `error_message` text DEFAULT NULL,
  `sent_by` int UNSIGNED DEFAULT NULL,
  `metadata` text DEFAULT NULL,
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
SQL
        );

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `communication_logs`
  ADD PRIMARY KEY (`id`),
  ADD KEY `communication_logs_student_id` (`student_id`),
  ADD KEY `communication_logs_family_id` (`family_id`),
  ADD KEY `communication_logs_sent_by` (`sent_by`);
SQL
        );

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `communication_logs`
  MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT;
SQL
        );
    }

    public function down(): void
    {
        Schema::dropIfExists('communication_logs');
    }
};
