<?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;

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

    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();
    }
}
