<?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 `inventory_categories` (
`id` int UNSIGNED NOT NULL,
  `type` enum('classroom','book','office','kitchen') NOT NULL DEFAULT 'office',
  `name` varchar(120) NOT NULL,
  `description` text,
  `grade_min` tinyint UNSIGNED DEFAULT NULL,
  `grade_max` tinyint UNSIGNED DEFAULT NULL,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
SQL
        );

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `inventory_categories`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `type_name` (`type`,`name`),
  ADD KEY `idx_cat_type_grade_range` (`type`,`grade_min`,`grade_max`);
SQL
        );

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

    }

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