<?php

namespace Database\Seeders;

use App\Models\SiteManagement;
use App\Models\SiteManagementComponent;
use App\Models\SiteManagementComponentField;
use App\Models\SiteManagementContentField;
use App\Models\SiteManagementFieldType;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class SiteManagementContentFieldSeeder extends Seeder {
	use WithoutModelEvents;
	/**
	 * Run the database seeds.
	 */
	public function run(): void {
		$siteManagementId_home = SiteManagement::where('route', 'home')->first()->id;
		$siteManagementComponent = [
			'banner' => SiteManagementComponent::where('value', 'site.components.banner')->first()->id,
			'container' => SiteManagementComponent::where('value', 'site.components.container')->first()->id,
			'about' => SiteManagementComponent::where('value', 'site.components.about')->first()->id,
		];

		$siteManagementComponentFields = SiteManagementComponentField::query()
			->whereIn('site_management_component_id', [
				$siteManagementComponent['banner'],
				$siteManagementComponent['container'],
				$siteManagementComponent['about'],
			])->get();

		foreach ($siteManagementComponentFields as $siteManagementComponentField) {
			SiteManagementContentField::updateOrcreate([
				'site_management_id' => $siteManagementId_home,
				'site_management_component_field_id' => $siteManagementComponentField->id,
				'site_management_field_type_id' => $siteManagementComponentField->site_management_field_type_id,
				'value' => null,
			], []);
		}
	}
}
