<?php

namespace App\Models;

use App\Traits\AmountAnalytics;
use App\Traits\RoleTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, RoleTrait, AmountAnalytics;

    protected $fillable = ['name', 'phone', 'password', 'is_blocked', 'role', 'balance', 'fcm'];

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

    protected $casts = [
        'phone_verified_at' => 'datetime',
        'password' => 'hashed',
    ];

    public function scopeAgents($query)
    {
        return $query->where('role', 'agent');
    }

    public function bettings()
    {
        return $this->hasMany(Betting::class, 'agent_id');
    }

    public function transactions()
    {
        return $this->hasMany(Transaction::class);
    }
}
