<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

class SeedOthersCategory20250428051008 extends Migration
{
    public function up(): void
    {
        // Insert a default section if it doesn't exist
        $sectionId = DB::table('sections')->insertGetId([
            'name' => 'General',
            'status' => 1,
            'created_at' => now(),
            'updated_at' => now(),
        ]);

        // Insert the "Others" category
        DB::table('categories')->insert([
            'section_id' => $sectionId,
            'parent_id' => 0,
            'name' => 'Others',
            'commission_rate' => 0.00,
            'url' => 'others',
            'status' => 1,
            'created_at' => now(),
            'updated_at' => now(),
        ]);
    }

    public function down(): void
    {
        DB::table('categories')->where('name', 'Others')->delete();
        DB::table('sections')->where('name', 'General')->delete();
    }
}