<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
    use HasFactory, Notifiable;

    protected $fillable = [
        'name',
        'email',
        'password',
        'role',
        'tanggal_lahir',
        'alamat',
        'diagnosis_cp',
        'riwayat_kehamilan',
        'riwayat_persalinan',
        'berat_badan_lahir',
        'keluhan_utama',
        'riwayat_penyakit_penyerta',
    ];

    protected $hidden = [
        'password',
        'remember_token',
    ];

    protected function casts(): array
    {
        return [
            'email_verified_at' => 'datetime',
            'tanggal_lahir' => 'date',
            'password' => 'hashed',
        ];
    }

    // ===============================
    // RELASI MONITORING (yang lama)
    // ===============================
    public function monitoringSebagaiPasien()
    {
        return $this->hasMany(Monitoring::class, 'patient_id');
    }

    public function monitoringSebagaiPetugas()
    {
        return $this->hasMany(Monitoring::class, 'created_by');
    }

    // ===============================
    // RELASI GMFM (yang baru)
    // ===============================
    public function penilaianGmfmSebagaiPasien()
    {
        return $this->hasMany(PenilaianGmfm::class, 'patient_id');
    }

    public function penilaianGmfmSebagaiTerapis()
    {
        return $this->hasMany(PenilaianGmfm::class, 'therapist_id');
    }
}
