<?php

namespace App\Classes\Modules\Warehouses\Services;


use App\Models\Warehouse;
use App\Http\Resources\Warehouse as WarehouseResource;
use Illuminate\Http\Request;


class UpdatesWarehouse
{
    /** @var  Warehouse */
    private $repository;

    /**
     * UpdatesWarehouse constructor.
     * @param Warehouse $repository
     */
    public function __construct(Warehouse $repository)
    {
        $this->repository = $repository;
    }


    public function execute(string $id, Request $request){


        $warehouse = $this->repository->findOrFail($id);

        $warehouse->name = $request->input('name');
        $warehouse->email = $request->input('email');
        $warehouse->street_one = $request->input('street_one');
        $warehouse->street_two = $request->input('street_two');
        $warehouse->city = $request->input('city');
        $warehouse->state = $request->input('state');
        $warehouse->post_code = $request->input('post_code');
        $warehouse->country = $request->input('country');

        if($warehouse->save()){
           return new WarehouseResource($warehouse);
        }
    }

}