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

    // Roles possibles
    public const ROLE_ADMIN = 'admin';
    public const ROLE_PARTNER = 'partner';
    public const ROLE_COURIER = 'courier';

    protected $fillable = [
        'name',
        'email',
        'password',
        'role',
        'partner_id',
        'phone',
        'active',
    ];

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

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

    public function partner()
    {
        return $this->belongsTo(Partner::class);
    }

    public function assignedRequests()
    {
        return $this->hasMany(ServiceRequest::class, 'assigned_courier_id');
    }

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

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

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