<?php

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

class CreateAccessoriesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('accessories', function (Blueprint $table) {
            $table->id();
            $table->foreignId('accessory_category_id')->constrained()->onDelete('cascade'); // Thuộc danh mục nào
			$table->string('code')->unique()->nullable(); // Mã phụ kiện
            $table->string('name'); // Tên phụ kiện
            $table->text('description')->nullable(); // Mô tả
            $table->string('image')->nullable(); // Hình ảnh
			$table->integer('position')->default(0); // Thứ tự hiển thị
			$table->boolean('is_activated')->default(true);
			$table->boolean('is_deleted')->default(false);
            $table->timestamps();
            
            $table->index(['accessory_category_id', 'code', 'name']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('accessories');
    }
}
