<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

/**
 * @method \Laravel\Sanctum\NewAccessToken createToken(string $name, array $abilities = ['*'])
 */
class User extends Authenticatable
{
    use HasApiTokens, Notifiable;

  //* Associated Table & Primary Key
    protected $table = 'users';
    protected $primaryKey = 'id';

  //* Fillable Fields
    protected $fillable = [
        'name',
        'last_name',
        'phone',
        'email',
        'password',
        'role',
        'report_permissions',
        'profile_photo',
        'shift_id',
    ];

  //* Hidden/Protected Fields
    protected $hidden = [
        'password', 'remember_token',
    ];

  //* Cast Columns
    protected $casts = [
        'email_verified_at' => 'datetime',
        'report_permissions' => 'array',
    ];

  //* Set Default Values
    protected $attributes = [
        'report_permissions' => '{"has_permission":false,"statistical_summaries":false,"general_reports":false,"income_reports":false,"booking_reports":false,"client_reports":false}',
    ];

  //* Relationships
    public function reservations() {
        return $this->hasMany(\App\Models\Hotel\Reservation::class, "receptionist_id");
    }

    public function externalReservations() {
        return $this->hasMany(\App\Models\Modules\OtaConnections\ExternalReservation::class, "receptionist_id");
    }

    public function audits() {
        return $this->hasMany(\App\Models\Modules\Audits\Audit::class);
    }

    public function shift() {
        return $this->belongsTo(\App\Models\Modules\Shift::class);
    }

}
