<?php

namespace App\Services;

use App\Models\LeasingRecord;
use App\Models\User;
use Illuminate\Support\Facades\Auth;

class LeasingDataService
{
    public function search($query)
    {
        return LeasingRecord::where('nopol', 'like', "%{$query}%")
            ->orWhere('chassis_number', 'like', "%{$query}%")
            ->orWhere('engine_number', 'like', "%{$query}%")
            ->get();
    }

    public function create(array $data)
    {
        $data['user_id'] = Auth::id();
        return LeasingRecord::create($data);
    }

    public function update(LeasingRecord $record, array $data)
    {
        $record->update($data);
        return $record;
    }

    public function delete(LeasingRecord $record)
    {
        return $record->delete();
    }

    public function getForLeasing(User $user)
    {
        return LeasingRecord::where('user_id', $user->id)->get();
    }
}
