<?php

namespace App\Jobs\Dashboard\Partner;

use App\Models\Partner;
use Illuminate\Support\Arr;
use App\Http\Requests\Dashboard\Partner\Update as Request;

class Update
{

    protected $partner;
    protected $attr;

    /**
     * Update constructor.
     * @param Partner $partner
     * @param array $attr
     */
    public function __construct(Partner $partner, array $attr = [])
    {
        $this->attr = Arr::only($attr, ['name', 'image', 'status', 'video_url', 'description', "position", 'is_price']);
        $this->partner = $partner;
    }

    /**
     * @param Partner $partner
     * @param Request $request
     * @param $path
     * @return Update
     */
    public static function fromRequest(Partner $partner, Request $request, $path)
    {
        return new static($partner, [
            'name' => $request->getName(),
            'image' => $path,
            'status' => $request->status,
            'video_url' => $request->video_url,
            'description' => $request->getDescription(),
            'position' => $request->position,
            'is_price' => $request->is_price == null ? false : true,
        ]);
    }


    /**
     *
     */
    public function handle()
    {
        $this->partner->update($this->attr);
    }
}
