<?php

namespace Booktics\Team_Member\Handlers;

use Booktics\Models\Team_Member_Model;

class Team_Member_Event_Handler {

    /**
     * Send invitation mail on team member creation
     *
     * @param $team_member_id
     *
     * @return bool
     */
    public function on_team_member_create( $team_member_id ) {
        $team_member = ( new Team_Member_Model() )->find( $team_member_id );
        $user        = get_user_by( 'ID', $team_member_id );
        if ( ! $user ) {
            return false;
        }
        $reset_key = get_password_reset_key( $user );
        $reset_url = network_site_url( "wp-login.php?action=rp&key=$reset_key&login=" . rawurlencode( $user->user_login ), 'login' );

        do_action(
            'booktics_gln_hook', 'team_member_created', array(
				'team_member_name'   => $team_member->display_name,
				'team_member_email'  => $team_member->user_email,
				'password_reset_url' => $reset_url,
            )
        );

        return true;
    }
}
