<?php

declare(strict_types=1);

namespace TechnoArtisan\FilamentCms\Database;

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

abstract class BaseMigration extends Migration
{
    protected const string TABLE              = '';
    protected const string BASE_TABLE_ENGINE  = 'InnoDB';
    protected const string BASE_CHARACTER_SET = 'utf8mb4';

    /**
     * utf8mb4_0900_as_cs
     *
     * utf8mb4: character set
     * 0900   : UCA 9.0.0 weight keys (Unicode Collation Algorithm version)
     * as     : accent-sensitive
     * cs     : case-sensitive
     *
     * @link https://dev.mysql.com/doc/refman/8.3/en/charset-collation-names.html
     */
//    protected const BASE_COLLATION = 'utf8mb4_0900_as_cs'; // Percona
    protected const string BASE_COLLATION = 'utf8mb4_unicode_ci';  // MySQL/MariaDB

    public function down(): void
    {
        Schema::dropIfExists(static::TABLE);
    }

    public function basicTableSetup(Blueprint $table): void
    {
        $table->engine(self::BASE_TABLE_ENGINE);   // ensure the best database engine is used
        $table->charset(self::BASE_CHARACTER_SET);
        $table->collation(self::BASE_COLLATION);  // also applies to the columns collation
    }
}
