<?php

namespace app\themes\svo\services;

use kernel\helpers\Debug;
use kernel\models\Option;
use kernel\modules\option\service\OptionService;
use kernel\modules\post\models\Post;

class SvoThemeService
{

    public static function getSliderPosts()
    {
        $slides = json_decode(OptionService::getItem('main_news_slider'), true);

        return Post::whereIn('id', $slides['ids'])->get();
    }

    public static function addPostSlide(int $postId)
    {
        $slides = json_decode(OptionService::getItem('main_news_slider'), true);

        if (!in_array($postId, $slides['ids'])) {
            $slides['ids'][] = $postId;
            OptionService::createOrUpdate('main_news_slider', json_encode($slides));
        }

        return $slides;
    }



}