<?php

namespace Database\Seeders;

use App\Models\Tenants\Position;
use Illuminate\Database\Seeder;

class PositionSeeder extends Seeder
{
    /**
     * Run the database seeds.
     * 직급(rank)과 직책(title) 기본 데이터 생성
     */
    public function run(): void
    {
        $tenantId = 287; // 프론트_테스트회사

        // 직급 (rank) - 기존 tenant_user_profiles.position_key와 매핑
        $ranks = [
            ['key' => 'STAFF', 'name' => '사원', 'sort_order' => 1],
            ['key' => 'SENIOR', 'name' => '주임', 'sort_order' => 2],
            ['key' => 'ASSISTANT_MANAGER', 'name' => '대리', 'sort_order' => 3],
            ['key' => 'MANAGER', 'name' => '과장', 'sort_order' => 4],
            ['key' => 'DEPUTY_MANAGER', 'name' => '차장', 'sort_order' => 5],
            ['key' => 'DIRECTOR', 'name' => '부장', 'sort_order' => 6],
            ['key' => 'EXECUTIVE', 'name' => '이사', 'sort_order' => 7],
            ['key' => 'SENIOR_EXECUTIVE', 'name' => '상무', 'sort_order' => 8],
            ['key' => 'VICE_PRESIDENT', 'name' => '전무', 'sort_order' => 9],
            ['key' => 'CEO', 'name' => '대표', 'sort_order' => 10],
        ];

        // 직책 (title)
        $titles = [
            ['key' => 'MEMBER', 'name' => '팀원', 'sort_order' => 1],
            ['key' => 'PART_LEADER', 'name' => '파트장', 'sort_order' => 2],
            ['key' => 'TEAM_LEADER', 'name' => '팀장', 'sort_order' => 3],
            ['key' => 'DEPARTMENT_HEAD', 'name' => '실장', 'sort_order' => 4],
            ['key' => 'DIVISION_HEAD', 'name' => '본부장', 'sort_order' => 5],
            ['key' => 'CEO', 'name' => '대표이사', 'sort_order' => 6],
        ];

        // 직급 생성
        foreach ($ranks as $rank) {
            Position::updateOrCreate(
                [
                    'tenant_id' => $tenantId,
                    'type' => 'rank',
                    'key' => $rank['key'],
                ],
                [
                    'name' => $rank['name'],
                    'sort_order' => $rank['sort_order'],
                    'is_active' => true,
                ]
            );
        }

        // 직책 생성
        foreach ($titles as $title) {
            Position::updateOrCreate(
                [
                    'tenant_id' => $tenantId,
                    'type' => 'title',
                    'key' => $title['key'],
                ],
                [
                    'name' => $title['name'],
                    'sort_order' => $title['sort_order'],
                    'is_active' => true,
                ]
            );
        }

        $this->command->info('Positions seeded: '.count($ranks).' ranks, '.count($titles).' titles');
    }
}
