<?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
    {
        if (Schema::hasTable('families')) {
            return;
        }

        App\Support\SqliteCompat::statement(<<<'SQL'
CREATE TABLE `families` (
`id` int UNSIGNED NOT NULL,
  `family_code` varchar(64) NOT NULL,
  `household_name` varchar(128) DEFAULT NULL,
  `address_line1` varchar(128) DEFAULT NULL,
  `address_line2` varchar(128) DEFAULT NULL,
  `city` varchar(64) DEFAULT NULL,
  `state` varchar(32) DEFAULT NULL,
  `postal_code` varchar(16) DEFAULT NULL,
  `country` varchar(64) DEFAULT NULL,
  `primary_phone` varchar(32) DEFAULT NULL,
  `preferred_lang` varchar(16) DEFAULT NULL,
  `preferred_contact_method` varchar(32) DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
SQL
        );


        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `families`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `family_code` (`family_code`);
SQL
        );

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `families`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=146;
SQL
        );

    }

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