<?php 

namespace App\Services ;
use App\Models\Services;
use App\Services\Base\BaseService;
use Carbon\Carbon;
class ServicesService extends BaseService {

    public function __construct() 
    {
        parent::__construct(Services::class);
    }
    public function create($data)
    {
        if (isset($data['image']))
    {
            $image = ImageService::upload_image($data['image'], 'services');
        } else {
            $image = null;
        }

        $services = Services::create([
            'image' => $image,
            'title' => $data['title'],
            'description' => $data['description'],
        ]);
        $services->save();

        return [];
    }

    public function updateServices(int $id, $data)
    {

        $services = Services::find($id);

        if (isset($data['image']))
         {
               $image = ImageService::update_image($data['image'], $services->image, 'services');
               $data['image'] = $image;
            
        }
        return $this->update($id,$data);

    }
    public function delete(int $id)
    {

        $services = Services::find($id);
        
        $services->delete();
        
        ImageService::delete_image($services->image);
        
        return [];
    }

}
