<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
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', 'empleado_id', 'activo',
    ];

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

    protected $casts = [
        'email_verified_at' => 'datetime',
        'password'          => 'hashed',
        'activo'            => 'boolean',
    ];

    public function empleado(): BelongsTo
    {
        return $this->belongsTo(Empleado::class);
    }

    /** Solo administrador */
    public function esAdmin(): bool
    {
        return $this->rol === 'admin';
    }

    /** Admin o supervisor: gestiona todo */
    public function esSupervisor(): bool
    {
        return in_array($this->rol, ['admin', 'supervisor']);
    }

    /** SST: solo reportes + su hoja de tiempo */
    public function esSST(): bool
    {
        return $this->rol === 'sst';
    }

    /** Puede ver secci¨Žn de reportes (supervisor o SST) */
    public function puedeVerReportes(): bool
    {
        return in_array($this->rol, ['admin', 'supervisor', 'sst']);
    }

    /** Puede gestionar config (empleados, periodos, CC, calendario) */
    public function puedeConfigurar(): bool
    {
        return in_array($this->rol, ['admin', 'supervisor']);
    }
}
