<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        $roles = [
            'System Admin',
            'Teller',
            'BM', // Branch Manager
            'Credit Officer',
            'Admin',
        ];

        $now = Carbon::now();

        foreach ($roles as $roleName) {
            if (!DB::table('roles')->where('name', $roleName)->exists()) {
                DB::table('roles')->insert([
                    'name' => $roleName,
                    'guard_name' => 'web', // Adjust if using another guard
                    'created_at' => $now,
                    'updated_at' => $now,
                ]);
            }
        }
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        $roles = [
            'System Admin',
            'Teller',
            'BM',
            'Credit Officer',
            'Admin',
        ];

        DB::table('roles')->whereIn('name', $roles)->delete();
    }
};
