<?php

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

return new class extends Migration
{
    public function up()
    {
        Schema::create('customer_groups', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->text('description')->nullable();
            $table->decimal('discount_percentage', 5, 2)->default(0);
            $table->boolean('has_free_shipping')->default(false);
            $table->json('permissions')->nullable();
            $table->timestamps();
        });

        Schema::create('customer_group_users', function (Blueprint $table) {
            $table->id();
            $table->foreignId('group_id')->constrained('customer_groups')->onDelete('cascade');
            $table->foreignId('user_id')->constrained()->onDelete('cascade');
            $table->timestamps();
        });
    }

    public function down()
    {
        Schema::dropIfExists('customer_group_users');
        Schema::dropIfExists('customer_groups');
    }
};