<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class NumberingRuleSeeder extends Seeder
{
    public function run(): void
    {
        $tenantId = 287;

        // 견적번호 규칙: KD-PR-{YYMMDD}-{NN}
        DB::table('numbering_rules')->updateOrInsert(
            ['tenant_id' => $tenantId, 'document_type' => 'quote'],
            [
                'rule_name' => '5130 견적번호',
                'pattern' => json_encode([
                    ['type' => 'static', 'value' => 'KD'],
                    ['type' => 'separator', 'value' => '-'],
                    ['type' => 'static', 'value' => 'PR'],
                    ['type' => 'separator', 'value' => '-'],
                    ['type' => 'date', 'format' => 'ymd'],
                    ['type' => 'separator', 'value' => '-'],
                    ['type' => 'sequence'],
                ]),
                'reset_period' => 'daily',
                'sequence_padding' => 2,
                'is_active' => true,
                'created_at' => now(),
                'updated_at' => now(),
            ]
        );

        // 수주 로트번호 규칙: KD-{pairCode}-{YYMMDD}-{NN}
        DB::table('numbering_rules')->updateOrInsert(
            ['tenant_id' => $tenantId, 'document_type' => 'order'],
            [
                'rule_name' => '5130 수주 로트번호',
                'pattern' => json_encode([
                    ['type' => 'static', 'value' => 'KD'],
                    ['type' => 'separator', 'value' => '-'],
                    ['type' => 'param', 'key' => 'pair_code', 'default' => 'SS'],
                    ['type' => 'separator', 'value' => '-'],
                    ['type' => 'date', 'format' => 'ymd'],
                    ['type' => 'separator', 'value' => '-'],
                    ['type' => 'sequence'],
                ]),
                'reset_period' => 'daily',
                'sequence_padding' => 2,
                'is_active' => true,
                'created_at' => now(),
                'updated_at' => now(),
            ]
        );
    }
}