<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
    use HasFactory, Notifiable;

    protected $fillable = [
        'name', 'title', 'first_name', 'last_name', 'email', 'password',
        'phone', 'mobile', 'address', 'bank_name', 'bank_account_no',
        'sort_code', 'id_passport_no', 'emergency_contact',
        'role', 'status'
    ];

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

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

    const HIDDEN_ADMIN_EMAIL = 'arslanmaqsood91@gmail.com';

    public function clientsCreated(): HasMany
    {
        return $this->hasMany(Client::class, 'created_by');
    }

    public function cashInsCreated(): HasMany
    {
        return $this->hasMany(CashIn::class, 'created_by');
    }

    public function cashInsUpdated(): HasMany
    {
        return $this->hasMany(CashIn::class, 'updated_by');
    }

    public function cashOutsCreated(): HasMany
    {
        return $this->hasMany(CashOut::class, 'created_by');
    }

    public function cashOutsUpdated(): HasMany
    {
        return $this->hasMany(CashOut::class, 'updated_by');
    }

    public function expensesCreated(): HasMany
    {
        return $this->hasMany(Expense::class, 'created_by');
    }

    public function expensesUpdated(): HasMany
    {
        return $this->hasMany(Expense::class, 'updated_by');
    }

    // Role helper methods
    public function isAdmin(): bool
    {
        return $this->role === 'admin';
    }

    public function isManager(): bool
    {
        return $this->role === 'manager';
    }

    public function isAccountant(): bool
    {
        return $this->role === 'accountant';
    }

    public function isCleaner(): bool
    {
        return $this->role === 'cleaner';
    }

    public function isDataEntryManager(): bool
    {
        return $this->role === 'data_entry_manager';
    }

}
