<?php

namespace LaraBB\Settings\Tasks\Prefix;

use LaraBB\Settings\Models\Prefix;

/**
 * Class UpdatePrefixTask
 * @package LaraBB\Settings\Tasks\Prefix
 */
class UpdateTask
{
    /**
     * @param Prefix $prefix
     * @param array $data
     * @return bool
     */
    public function run(Prefix $prefix, array $data): bool
    {
        $prefix->updated_uuid = $data['updated_uuid'];
        $prefix->prefix       = $data['prefix'] ?? $prefix->prefix;
        $prefix->display_style = $data['display_style'] ?? $prefix->display_style;
        if($prefix->save()) {
            $prefix->forums()->sync($data['forums'] ?? []);

            return true;
        }

        return false;
    }
}
