<?php

namespace App\Livewire\Forms\Studio\Setting;

use App\Settings\SocialSettings;
use Livewire\Form;

class SocialForm extends Form
{
    public ?string $facebook = null;

    public ?string $instagram = null;

    public ?string $youtube = null;

    public ?string $tiktok = null;

    public ?string $whatsapp = null;

    public ?string $telegram = null;

    protected function rules(): array
    {
        return [
            'facebook' => ['nullable', 'url'],
            'instagram' => ['nullable', 'url'],
            'youtube' => ['nullable', 'url'],
            'tiktok' => ['nullable', 'url'],
            'whatsapp' => ['required', 'url'],
            'telegram' => ['nullable', 'url'],
        ];
    }

    public function setSettings(SocialSettings $settings): void
    {
        $this->facebook = $settings->facebook;
        $this->instagram = $settings->instagram;
        $this->youtube = $settings->youtube;
        $this->tiktok = $settings->tiktok;
        $this->whatsapp = $settings->whatsapp;
        $this->telegram = $settings->telegram;
    }

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

        $settings->facebook = $this->facebook;
        $settings->instagram = $this->instagram;
        $settings->youtube = $this->youtube;
        $settings->tiktok = $this->tiktok;
        $settings->whatsapp = $this->whatsapp;
        $settings->telegram = $this->telegram;

        $settings->save();
    }
}
