<?php

namespace App\Observers;

use App\Models\SecurityManagement\Role;
use App\Models\UserManagement\User;
use App\Models\UserManagement\UserType;

class UserObserver{

    /**
     * @param User $user
     * @return User
     */
    public function creating(User $user){

        $attributes = $user->getAttributes();

        if (isset($attributes["email"]) and !isset($attributes['password'])){
         //  $user->setAttribute("password",bcrypt($attributes['email']));
        }
        return $user;
    }

    /**
     * @param User $user
     * @return User
     */
    public function created(User $user){

        if ($user->isCustomer()){
            $user->assignRole(Role::CUSTOMER);
        }
        return $user;

    }


    public function deleted(User $user){
        $user->media()->delete();
    }
}
