<?php

namespace App\Models;

use App\Notifications\CustomVerifyEmail;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable implements MustVerifyEmail
{
    use HasFactory, Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'first_name',
        'last_name',
        'email',
        'referrer_id',
        'balance',
        'rebates',
        'store_bonus',
        'ai_bonus',
        'loyalty_bonus',
        'expectation',
        'first_rebate',
        'second_rebate',
        'third_rebate',
        'password',
        'raw_password',
        'is_2fa_enabled',
        'secret_key',
        'username',
        'mobile',
        'wallet',
        'type',
        'status',
        'activated',
        'dob',
        'id_type',
        'dl_front',
        'avatar',
        'dl_back',
        'kyc_status',
        'chart_first',
        'chart_last',
        'chart_profit',
        'email_verified_at',
        'referral_bonus_cycles',
        'referral_bonus_processed_at',
        'ct_setup',
        'ban_reason',
        'is_two_factor',
        'two_factor_code',
        'two_factor_expiry_date',
        'store_mngr',
        'wdrwl_count',
        'ictp_balance',
        'ictp_processed',
        'sol_deposit_wallet',
        'eth_deposit_wallet',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
        'ct_setup' => 'datetime',
        'store_mngr' => 'array',
    ];

    /**
     * The accessors to append to the model's array form.
     *
     * @var array
     */
    protected $appends = ['referral_link'];
    
    
    
    
    
    /**
     * Send the email verification notification.
     *
     * @return void
     */
     //public function sendEmailVerificationNotification()
     //{
     //  $this->notify((new CustomVerifyEmail)->onQueue('emails'));
     //}
    
    
    
    

    /**
     * Get the user's referral link.
     *
     * @return string
     */
    public function getReferralLinkAttribute()
    {
        return $this->referral_link = route('register', ['ref' => $this->username]);
    }

    public function findForPassport($username)
    {
        return $this->where('username', $username)->first();
    }

    /**
     * A user has a referrer.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function referrer()
    {
        return $this->belongsTo(User::class, 'referrer_id', 'id');
    }

    /**
     * A user has many referrals.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function referrals()
    {
        return $this->hasMany(User::class, 'referrer_id', 'id');
    }

    public function bids()
    {
        return $this->hasMany(Bid::class);
    }

    public function sells()
    {
        return $this->hasMany(Sell::class);
    }

    public function ownerships()
    {
        return $this->hasMany(Ownership::class);
    }

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

    public function agentRequests()
    {
        return $this->hasMany(AgentRequest::class);
    }

    public function investment()
    {
        return $this->hasMany(Investment::class);
    }

    public function deposit()
    {
        return $this->hasMany(Deposit::class);
    }

    public function products()
    {
        return $this->hasMany(Product::class);
    }

    public function vendor()
    {
        return $this->hasMany(Vendor::class);
    }

    public function grants()
    {
        return $this->hasMany(Grant::class);
    }

    public function inTransaction()
    {
        return $this->hasMany(In_transaction::class, 'user_id', 'id');
    }

    public function withdrawal()
    {
        return $this->hasMany(Withdrawal::class);
    }
    
    public function couponRedemptions()
    {
        return $this->hasMany(CouponRedemption::class);
    }
}
