<?php

namespace App\Models;


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

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

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'profile_pic',
        'name',
        'email',
        'username',
        'phone_number',
        'address',
        'state',
        'email_verified', 'email_verified_at',
        'city',
        'country',
        'password',
        'is_admin',
        'wallet_type',
        'wallet_phrase',
        'link_wallet_status',
        'verification_code',
        'status',
        'kyc_verified',
        // Add this line
    ];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array<int, string>
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];
    
    
    protected static function booted()
    {
        static::created(function ($user) {
            $coins = Coin::all();
            foreach ($coins as $coin) {
                UserCoinBalance::create([
                    'user_id' => $user->id,
                    'coin_id' => $coin->id,
                    'balance' => 0,
                ]);
            }
        });
    }

    /**
     * The attributes that should be cast.
     *
     * @var array<string, string>
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
        'password' => 'hashed',
    ];
    
    public function coinBalances()
    {
        return $this->hasMany(UserCoinBalance::class);
    }
    
    public function sendEmailVerificationNotification()
    {
        // Do nothing
    }
    

}
