<?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; // ⬅️ WAJIB ADA INI

    protected $fillable = [
        'nama',   // ganti dari nama → name (lebih aman ikut default Laravel)
        'email',
        'password',
        'role'
    ];

    protected $hidden = [
        'password'
    ];

    public function keranjangs()
    {
        return $this->hasMany(Keranjang::class, 'id_users');
    }

    public function pesanans()
    {
        return $this->hasMany(Pesanan::class);
    }

    public function alamats()
    {
        return $this->hasMany(AlamatUser::class);
    }

    public function alamatUtama()
    {
        return $this->hasOne(AlamatUser::class)->where('is_utama', true);
    }
}
