<?php

namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable;

    protected $fillable = ['name', 'email', 'password', 'rol_id', 'activo'];
    protected $hidden   = ['password', 'remember_token'];

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

    // Helper para el frontend: devuelve 'nombre' en lugar de 'name'
    public function toFrontend(): array
    {
        return [
            'id'     => $this->id,
            'nombre' => $this->name,
            'email'  => $this->email,
            'rol_id' => $this->rol_id,
            'activo' => $this->activo,
        ];
    }
}
