<?php

namespace App\Services\System\Setting;

use App\Services\Concerns\CachesQuery;
use App\Settings\SocialMediaSettings;

class SocialMediaService
{
    use CachesQuery;

    public function socialMediaData(): array
    {
        return $this->cacheRemember('system:social_media', 86400, function () {
            $settings = app(SocialMediaSettings::class);

            return [
                'instagram_url' => $settings->instagram_url,
                'facebook_url' => $settings->facebook_url,
                'tiktok_url' => $settings->tiktok_url,
            ];
        });
    }

    public function updateSocialMedia(array $validated): void
    {
        $settings = app(SocialMediaSettings::class);

        $settings->instagram_url = $validated['instagram_url'] ?? null;
        $settings->facebook_url = $validated['facebook_url'] ?? null;
        $settings->tiktok_url = $validated['tiktok_url'] ?? null;

        $settings->save();

        $this->cacheForget('system:social_media');
        $this->cacheForget('homepage:page_data');
    }
}
