<?php

namespace App\Modules\Patient\Repositories;

use App\Core\Base\BaseRepository;
use App\Models\Patient;
use Illuminate\Database\Eloquent\Collection;

class PatientRepository extends BaseRepository
{
    public function __construct(Patient $model)
    {
        parent::__construct($model);
    }

    public function search(string $query): Collection
    {
        return $this->model->where('name', 'LIKE', "%{$query}%")
            ->orWhere('phone', 'LIKE', "%{$query}%")
            ->orWhere('patient_uid', 'LIKE', "%{$query}%")
            ->get();
    }

    public function getWithHistory(int|string $id): ?Patient
    {
        return $this->model->with(['visits', 'prescriptions', 'invoices'])->find($id);
    }
}
