<?php

declare(strict_types=1);

namespace App\Framework\Database\Platform\Enums;

/**
 * Database index types
 */
enum IndexType: string
{
    case PRIMARY = 'primary';
    case UNIQUE = 'unique';
    case INDEX = 'index';
    case FULLTEXT = 'fulltext';
    case SPATIAL = 'spatial';

    public function isUnique(): bool
    {
        return match($this) {
            self::PRIMARY, self::UNIQUE => true,
            default => false
        };
    }

    public function requiresSpecialEngine(): bool
    {
        return match($this) {
            self::FULLTEXT, self::SPATIAL => true,
            default => false
        };
    }

    public function getKeyword(): string
    {
        return match($this) {
            self::PRIMARY => 'PRIMARY KEY',
            self::UNIQUE => 'UNIQUE KEY',
            self::INDEX => 'KEY',
            self::FULLTEXT => 'FULLTEXT KEY',
            self::SPATIAL => 'SPATIAL KEY'
        };
    }
}
