<?php

namespace App\Livewire\Forms\Studio\Setting;

use App\Settings\GeneralSettings;
use Livewire\Form;

class GeneralForm extends Form
{
    public string $site_name = '';

    public string $site_tagline = '';

    public string $site_description = '';

    public bool $maintenance_mode = false;

    public function rules(): array
    {
        return [
            'site_name' => ['required', 'string', 'max:100'],
            'site_tagline' => ['required', 'string', 'max:150'],
            'site_description' => ['required', 'string'],
            'maintenance_mode' => ['required', 'boolean'],
        ];
    }

    public function setSettings(GeneralSettings $settings): void
    {
        $this->site_name = $settings->site_name;
        $this->site_tagline = $settings->site_tagline;
        $this->site_description = $settings->site_description;
        $this->maintenance_mode = $settings->maintenance_mode;
    }

    public function update(GeneralSettings $settings): void
    {
        $this->validate();

        $settings->site_name = $this->site_name;
        $settings->site_tagline = $this->site_tagline;
        $settings->site_description = $this->site_description;
        $settings->maintenance_mode = $this->maintenance_mode;

        $settings->save();
    }
}
