<?php

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

return new class extends Migration
{
    public function up(): void
    {
        // 근태신청 결재 양식 (출장/재택/외근/조퇴)
        DB::table('approval_forms')->insertOrIgnore([
            'tenant_id' => 1,
            'name' => '근태신청',
            'code' => 'attendance_request',
            'category' => 'request',
            'template' => json_encode([
                'fields' => [
                    ['name' => 'user_name', 'type' => 'text', 'label' => '신청자'],
                    ['name' => 'request_type', 'type' => 'text', 'label' => '신청유형'],
                    ['name' => 'period', 'type' => 'text', 'label' => '기간'],
                    ['name' => 'days', 'type' => 'number', 'label' => '일수'],
                    ['name' => 'reason', 'type' => 'text', 'label' => '사유'],
                ],
            ], JSON_UNESCAPED_UNICODE),
            'is_active' => true,
            'created_by' => 1,
            'created_at' => now(),
            'updated_at' => now(),
        ]);

        // 사유서 결재 양식 (지각사유서/결근사유서)
        DB::table('approval_forms')->insertOrIgnore([
            'tenant_id' => 1,
            'name' => '사유서',
            'code' => 'reason_report',
            'category' => 'request',
            'template' => json_encode([
                'fields' => [
                    ['name' => 'user_name', 'type' => 'text', 'label' => '신청자'],
                    ['name' => 'report_type', 'type' => 'text', 'label' => '사유서유형'],
                    ['name' => 'target_date', 'type' => 'date', 'label' => '대상일'],
                    ['name' => 'reason', 'type' => 'text', 'label' => '사유'],
                ],
            ], JSON_UNESCAPED_UNICODE),
            'is_active' => true,
            'created_by' => 1,
            'created_at' => now(),
            'updated_at' => now(),
        ]);
    }

    public function down(): void
    {
        DB::table('approval_forms')
            ->where('tenant_id', 1)
            ->whereIn('code', ['attendance_request', 'reason_report'])
            ->delete();
    }
};
