<?php

namespace Database\Seeders;

use App\Models\Registrar;
use App\Models\RegistrarSetting;
use Illuminate\Database\Seeder;

class RegistrarSettingSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        // Namecheap ayarları
        $namecheap = Registrar::where('name', 'namecheap')->first();
        if ($namecheap) {
            $namecheapSettings = [
                ['setting' => 'username', 'value' => 'namecheap_username'],
                ['setting' => 'apikey', 'value' => 'namecheap_apikey'],
                ['setting' => 'clientip', 'value' => '127.0.0.1'],
                ['setting' => 'sandbox', 'value' => 'true'],
            ];

            foreach ($namecheapSettings as $setting) {
                RegistrarSetting::updateOrCreate(
                    [
                        'registrar_id' => $namecheap->id,
                        'setting' => $setting['setting'],
                    ],
                    [
                        'registrar_id' => $namecheap->id,
                        'setting' => $setting['setting'],
                        'value' => $setting['value'],
                    ]
                );
            }
        }

        // ResellerClub ayarları
        $resellerclub = Registrar::where('name', 'resellerclub')->first();
        if ($resellerclub) {
            $resellerclubSettings = [
                ['setting' => 'userid', 'value' => 'resellerclub_userid'],
                ['setting' => 'apikey', 'value' => 'resellerclub_apikey'],
                ['setting' => 'sandbox', 'value' => 'true'],
            ];

            foreach ($resellerclubSettings as $setting) {
                RegistrarSetting::updateOrCreate(
                    [
                        'registrar_id' => $resellerclub->id,
                        'setting' => $setting['setting'],
                    ],
                    [
                        'registrar_id' => $resellerclub->id,
                        'setting' => $setting['setting'],
                        'value' => $setting['value'],
                    ]
                );
            }
        }
    }
}
