<?php

namespace App\Actions\Jetstream;
use Laravel\Jetstream\Contracts\DeletesUsers;
use App\Models\Courir_tracking;
use App\Models\Deposit;

class DeleteUser implements DeletesUsers
{
    /**
     * Delete the given user.
     *
     * @param  mixed  $user
     * @return void
     */
    public function delete($user)
    {    
        $deposits=Deposit::where('user',$user->id)->get();
        if(!empty($deposits)){
            foreach($deposits as $deposit){
                Deposit::where('id', $deposit->id)->delete();
            }
        }

        $trackings = Courir_tracking::where('user', $user->id)->get();
        if(!empty($trackings)){
            foreach($trackings as $tracking){
                Courir_tracking::where('id', $tracking->id)->delete();
            }
        }
        
        $user->deleteProfilePhoto();
        $user->tokens->each->delete();
        $user->delete();
    }
}
