<?php

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

return new class extends Migration
{
    public function up(): void
    {
        $now = now();

        // position_type 코드 그룹 (직급/직책 구분)
        $positionTypes = [
            ['code' => 'rank', 'name' => '직급', 'sort_order' => 1],
            ['code' => 'title', 'name' => '직책', 'sort_order' => 2],
        ];

        foreach ($positionTypes as $item) {
            DB::table('common_codes')->updateOrInsert(
                ['code_group' => 'position_type', 'code' => $item['code']],
                [
                    'code_group' => 'position_type',
                    'code' => $item['code'],
                    'name' => $item['name'],
                    'sort_order' => $item['sort_order'],
                    'is_active' => true,
                    'created_at' => $now,
                    'updated_at' => $now,
                ]
            );
        }
    }

    public function down(): void
    {
        DB::table('common_codes')->where('code_group', 'position_type')->delete();
    }
};
