<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        $now = now();

        // delivery_method 코드 그룹 (배송방식)
        $deliveryMethods = [
            ['code' => 'direct', 'name' => '상차', 'sort_order' => 1],
            ['code' => 'pickup', 'name' => '택배', 'sort_order' => 2],
        ];

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

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        DB::table('common_codes')->where('code_group', 'delivery_method')->delete();
    }
};
