<?php

namespace LaraBB\Category\Tasks;

use LaraBB\Category\Models\Category;

/**
 * Class StoreCategoryTask
 * @package LaraBB\Category\Tasks
 */
class StoreTask
{
    /**
     * @var Category
     */
    private Category $category;

    /**
     * StoreCategoryTask constructor.
     * @param Category $category
     */
    public function __construct(Category $category)
    {
        $this->category = $category;
    }

    /**
     * @param array $data
     * @return Category
     */
    public function run(array $data = []): Category
    {
        $this->category->created_uuid = $data['created_uuid'];
        $this->category->updated_uuid = $data['updated_uuid'];
        $this->category->title        = $data['title'];
        $this->category->slug         = $data['slug'];
        $this->category->save();

        return $this->category;
    }
}
