<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * @property string $id
 * @property string $firstname
 * @property string $lastname
 * @property string $age
 * @property string $gender
 * @property string $email
 * @property string $phone
 * @property string $birthday
 * @property string $created_at
 * @property string $updated_at
 * @property Appointment[] $appointments
 * @property History[] $histories
 * @property Relationship[] $relationships
 */
class Patients extends Model
{
    /**
     * 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 = ['id','firstname', 'lastname', 'age', 'gender', 'email', 'phone', 'birthday', 'created_at', 'updated_at'];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function appointments()
    {
        return $this->hasMany('App\Appointment', 'patients_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function histories()
    {
        return $this->hasMany('App\History', 'patients_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function relationships()
    {
        return $this->hasMany('App\Relationship', 'patients_id');
    }

    /**
     * 
     */
    public static function factoryCreate($data){
        $patient = [];
        $patient["id"]        = md5($data["nationality"] . $data["identification"] . $data["patientFirstName"] . $data["patientLastName"]);
        $patient["firstname"] = $data["patientFirstName"];
        $patient["lastname"]  = $data["patientLastName"];
        $patient["age"]       = $data["patientAge"];
        $patient["gender"]    = $data["patientGender"];
        $patient["email"]     = NULL;
        $patient["phone"]     = NULL;
        $patient["birthday"]  =  date_create_from_format('d/m/Y',$data["birthday"]);
        return $patient;
    }
}
