<?php
namespace ZenCommunity\Addons\Tutorlms\Feeds;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class CourseCompletedFeed extends Abstracts\EventFeed {
	public function init(): void {
		add_action(
			'tutor_course_complete_after',
			[ $this, 'notify' ],
			10, 2
		);
	}

	public function notify( int $course_id, int $user_id  ): void {
		$this->course_id = $course_id;
		$course_permalink = get_permalink( $this->course_id );
		$course_title = get_the_title( $this->course_id );
		// $quiz_title = get_the_title( $quiz_id );
		$user = get_user( $user_id  );
		$this->title     = sprintf(
			/* translators:  %s is the username, %s is the course name */
			__( '%1$s has just completed @ %2$s!', 'zencommunity' ),
			esc_html( $user ? $user->display_name : '' ),
			esc_html( $course_title )
		);
		$this->message   = sprintf(
			/* translators:  %s is the username, %s is the course name */
			__( '🎉 Congratulations on completing %1$s, %2$s! Your dedication and hard work truly paid off. We’re proud of your achievement—well done! 🚀', 'zencommunity' ),
			esc_html( $course_title ),
			esc_html( $user ? $user->display_name : '' )
		);
		$this->event     = 'course_complete';
		$this->push();
	}
}
