<?php
namespace App\Models;

use App\Traits\Auditable;

use Illuminate\Database\Eloquent\Model;
use App\Models\Interfaces\IPostCreateAppointmentStructure;

/**
 * @property string $representative_id
 * @property string $patients_id
 * @property string $title
 * @property string $description
 * @property string $created_at
 * @property string $updated_at
 * @property Patient $patient
 * @property Representative $representative
 */
class RelationShip extends Model implements IPostCreateAppointmentStructure
{
    use Auditable;
    /**
     * The table associated with the model.
     * 
     * @var string
     */
    protected $table = 'relationship';

    /**
     * @var array
     */
    protected $fillable = ['representative_id','patients_id','title', 'description', 'created_at', 'updated_at'];

    public $incrementing = false; // Le dice a Laravel que no es autoincremental
    protected $keyType = 'string'; // Importante si tus PKs son UUIDs/strings

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function patient()
    {
        return $this->belongsTo('App\Models\Patient', 'patients_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function representative()
    {
        return $this->belongsTo('App\Models\Representative');
    }

    /**
     * 
     */
    public static function getStructureFromRequest(array $data,array $extras):array{
        $relationShip = [];
        $relationShip["representative_id"]  = $extras["representativeId"];
        $relationShip["patients_id"]        = $extras["patientsId"];
        $relationShip["title"]              = $data["relationship"];
        $relationShip["description"]        = $data["relationship"];
        return $relationShip;
    }

    public static function getDataFromModel($representativeId,$data):array{
        $relationShip = [];
        $relationShip["representative_id"]  = $representativeId;
        $relationShip["patients_id"]        = $data["patient_id"];
        $relationShip["title"]              = $data["parent"];
        $relationShip["description"]        = $data["parent"];
        return $relationShip;
    }
}
