<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        $roles = [
            'super-admin' => '系統管理員',
            'admin' => '一般管理員',
            'warehouse-manager' => '倉庫管理員',
            'purchaser' => '採購人員',
            'viewer' => '檢視人員',
        ];

        foreach ($roles as $name => $displayName) {
            DB::table('roles')
                ->where('name', $name)
                ->update(['display_name' => $displayName]);
        }
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
         $roles = [
            'super-admin',
            'admin',
            'warehouse-manager',
            'purchaser',
            'viewer',
        ];

        DB::table('roles')
            ->whereIn('name', $roles)
            ->update(['display_name' => null]);
    }
};
