<?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;

class User extends Authenticatable
{
    /** @use HasFactory<\Database\Factories\UserFactory> */
    use HasFactory, Notifiable;
    public const ROLE_USER = 'user';
    public const ROLE_SECRETARY = 'secretaire';
    public const ROLE_VRAA = 'vr-aa';
    public const ROLE_CHEF = 'chef-institution';
     public const ROLE_ADMIN = 'admin';

    public function isSecretary(): bool
    {
        return $this->role === self::ROLE_SECRETARY && is_null($this->institution_id);
    }

    public function isVRaa(): bool
    {
        return $this->role === self::ROLE_VRAA && is_null($this->institution_id);
    }

    public function isChefInstitution(): bool
    {
        return $this->role === self::ROLE_CHEF;
    }

    
    /**
     * The attributes that are mass assignable.
     *
     * @var list<string>
     */
    protected $fillable = [
        'name',
        'email',
        'password',
        'mobile',
        'role',
        'institution_id',
        'service_id',
        'status'
    ];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var list<string>
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * Get the attributes that should be cast.
     *
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'email_verified_at' => 'datetime',
            'password' => 'hashed',
        ];
    }

    public function institution()
    {
        return $this->belongsTo(Institution::class);
    }

    public function canValidateUsers(): bool
    {
        return $this->isVraa() || $this->isSecretary();
    }

    public function service()
    {
        return $this->belongsTo(Service::class);
    }

}
