<?php

namespace App\Models;

use App\Traits\Auditable;

use Illuminate\Database\Eloquent\Model;
use App\Models\Interfaces\IPostCreateAppointmentStructure;
use Exception;
use DateTime;
use App\Helper\Helper;

/**
* @property string $appointment_id
* @property string $patient_id
* @property string $patientEmail
* @property string $usersEmail
* @property string $user_id
* @property string $identification
* @property string $firstname
* @property string $lastname
* @property string $age
* @property string $gender
* @property string $phone
* @property string $birthday
* @property string $blood_type
* @property string $address
* @property string $patientCreatedAt
* @property string $patientUpdatedAt
* @property Appointment[] $appointments
* @property History[] $histories
* @property Relationship[] $relationships
*/
class PatientsByDoctor extends Model
{
    use Auditable;

    protected $table = 'patients_by_doctors';

    // Modelo User.php
protected $dateFormat = 'Y-m-d H:i:s.u'; // Formato con microsegundos

    /**
     * The "type" of the auto-incrementing ID.
     * 
     * @var string
     */
    protected $keyType = 'string';

    /**
     * Indicates if the IDs are auto-incrementing.
     * 
     * @var bool
     */
    public $incrementing = false;

    /**
     * @var array
     */
    protected $fillable = [
        'appointment_id',
        'patient_id',
        'patientEmail',
        'usersEmail',
        'user_id',
        'identification',
        'firstname',
        'lastname',
        'age',
        'gender',
        'phone',
        'birthday',
        'blood_type',
        'address',
        'patientCreatedAt',
        'patientUpdatedAt'
        ];



         /**
     * 
     */
    public static function getPatientsMinorThat18($userId = NULL){
        $patient = NULL;
        $patient = (!isset($userId)) ? PatientsByDoctor::where("age", "<", 18)->get() : PatientsByDoctor::where("age", "<", 18)->where("user_id", "=", $userId)->get();
        return $patient;
    }

    /**
     * 
     */
    public static function getPatientsMajorThat18($userId = NULL){
        $patient = NULL;
        $patient = (!isset($userId)) ? PatientsByDoctor::where("age", ">", 17)->get() : PatientsByDoctor::where("age", ">", 17)->where("user_id", "=", $userId)->get();
        return $patient;
    }

   
}
