<?php

namespace kernel\app_modules\slider\services;

use kernel\app_modules\slider\models\Slider;
use kernel\helpers\Debug;
use kernel\helpers\Slug;
use kernel\modules\post\models\Post;
use kernel\FormModel;

class SliderService
{
    public function create(FormModel $form_model): false|Slider
    {
        $model = new Slider();
        $model->title = $form_model->getItem('title');
        $model->content = $form_model->getItem('content');
        $model->additional_information = $form_model->getItem('additional_information');
        $model->link = $form_model->getItem('link');
        if ($model->save()){
            return $model;
        }

        return false;
    }

    public function update(FormModel $form_model, Slider $slider): false|Slider
    {
        $slider->title = $form_model->getItem('title');
        $slider->content = $form_model->getItem('content');
        $slider->additional_information = $form_model->getItem('additional_information');
        $slider->link = $form_model->getItem('link');
        if ($slider->save()){
            return $slider;
        }

        return false;
    }
}