<?php

namespace Database\Seeders;

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

class SettingSeeder extends Seeder
{
    public function run(): void
    {
        $now = now();

        $settings = [
            [
                'key' => 'company_name',
                'value' => 'شرکت نرم‌افزاری پیشگام',
                'group' => 'general',
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'key' => 'company_phone',
                'value' => '021-12345678',
                'group' => 'general',
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'key' => 'company_address',
                'value' => 'تهران، خیابان ولیعصر، برج فناوری، طبقه ۵',
                'group' => 'general',
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'key' => 'company_logo',
                'value' => 'logos/company.png',
                'group' => 'general',
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'key' => 'job_titles',
                'value' => json_encode(['مدیر سیستم', 'مدیر پروژه', 'توسعه‌دهنده', 'کارشناس', 'مدیرعامل'], JSON_UNESCAPED_UNICODE),
                'group' => 'people',
                'type' => 'list',
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'key' => 'default_task_statuses',
                'value' => json_encode(['todo', 'in_progress', 'waiting', 'review', 'done']),
                'group' => 'task',
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'key' => 'default_priorities',
                'value' => json_encode(['low', 'medium', 'high', 'urgent']),
                'group' => 'task',
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'key' => 'default_project_statuses',
                'value' => json_encode(['planning', 'in_progress', 'on_hold', 'completed', 'cancelled']),
                'group' => 'project',
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'key' => 'risk_levels',
                'value' => json_encode(['low', 'medium', 'high']),
                'group' => 'project',
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'key' => 'backlog_types',
                'value' => json_encode(['idea', 'feature', 'bug', 'improvement', 'task']),
                'group' => 'backlog',
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'key' => 'backlog_statuses',
                'value' => json_encode(['active', 'converted']),
                'group' => 'backlog',
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'key' => 'notification_types',
                'value' => json_encode(['task_assigned', 'task_overdue', 'meeting_created', 'mention']),
                'group' => 'notification',
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'key' => 'smtp_settings',
                'value' => json_encode([
                    'host' => 'smtp.pishgam.com',
                    'port' => 587,
                    'encryption' => 'tls',
                ]),
                'group' => 'mail',
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'key' => 'working_days',
                'value' => json_encode(['saturday', 'sunday', 'monday', 'tuesday', 'wednesday'], JSON_UNESCAPED_UNICODE),
                'group' => 'calendar',
                'type' => 'list',
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'key' => 'organization_timezone',
                'value' => 'Asia/Tehran',
                'group' => 'calendar',
                'type' => 'string',
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'key' => 'default_meeting_reminder_minutes',
                'value' => '30',
                'group' => 'meeting',
                'type' => 'number',
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'key' => 'meeting_effectiveness_enabled',
                'value' => 'true',
                'group' => 'meeting',
                'type' => 'boolean',
                'created_at' => $now,
                'updated_at' => $now,
            ],
            [
                'key' => 'sprint_health_override_requires_reason',
                'value' => 'true',
                'group' => 'sprint',
                'type' => 'boolean',
                'created_at' => $now,
                'updated_at' => $now,
            ],
        ];

        foreach ($settings as $setting) {
            DB::table('settings')->updateOrInsert(['key' => $setting['key']], $setting);
        }
    }
}
