<?php

namespace App\Jobs\Dashboard\Service;

use App\Models\Service;
use Illuminate\Support\Arr;
use App\Http\Requests\Dashboard\Service\Store as Request;

class Store
{
    protected $attr;

    /**
     * Store constructor.
     * @param array $attr
     */
    public function __construct(array $attr = [])
    {
        $this->attr = Arr::only($attr, ['name', 'image', 'type', 'status', 'position', 'is_power']);
    }

    /**
     * @param Request $request
     * @param $path
     * @return Store
     */
    public static function fromRequest(Request $request, $path)
    {
        return new static([
            'name' => $request->getName(),
            'image' => $path,
            'status' => $request->status,
            'position' => $request->getPosition(),
            'is_power' => $request->is_power == null ? false : true,
            'type' => $request->generateSlug(),
        ]);
    }

    /**
     *
     */
    public function handle()
    {
        return Service::create($this->attr);
    }
}
