<?php

namespace WPD_Platform\Integrations\Lifterlms;

use Dollie\SDK\Attributes\Integration;
use Dollie\SDK\Controllers\IntegrationsController;
use Dollie\SDK\Base\BaseIntegration;
use Dollie\SDK\Traits\SingletonLoader;

#[Integration(
    id: 'LifterLMS',
    name: 'Lifterlms',
    slug: 'lifterlms',
    since: '1.0.0'
)]
/**
 * LifterLMS core integrations file
 *
 * @since 1.0.0
 */
class LifterLMS extends BaseIntegration
{
    use SingletonLoader;

    /**
     * ID
     *
     * @var string
     */
    protected $id = 'LifterLMS';

    /**
     * DollieTrigger constructor.
     */
    public function __construct()
    {
        $this->name = __('LifterLMS', 'dollie');
        $this->description = __('Easily Create And Sell Online Courses On Your WP Site With LifterLMS.', 'dollie');
        $this->icon_url = DOLLIE_SDK_URL . 'assets/icons/lifterlms.svg';

    }

    /**
     * Get course context data.
     *
     * @param int $course_id course.
     *
     * @return array
     */
    public static function get_lms_course_context($course_id)
    {

        $courses = get_post($course_id);
        if (! $courses instanceof \WP_Post) {
            return [];
        }
        $context['course'] = $courses->ID;
        $context['course_name'] = $courses->post_name;
        $context['course_title'] = $courses->post_title;
        $context['course_url'] = get_permalink($course_id);

        return $context;
    }

    /**
     * Get lesson context data.
     *
     * @param int $lesson_id lesson.
     *
     * @return array
     */
    public static function get_lms_lesson_context($lesson_id)
    {

        $lesson = get_post($lesson_id);
        if (! $lesson instanceof \WP_Post) {
            return [];
        }
        $context['lesson'] = $lesson->ID;
        $context['lesson_name'] = $lesson->post_name;
        $context['lesson_title'] = $lesson->post_title;
        $context['lesson_url'] = get_permalink($lesson_id);

        return $context;
    }

    /**
     * Get membership context data.
     *
     * @param int $membership_id membership.
     *
     * @return array
     */
    public static function get_lms_membership_context($membership_id)
    {

        $membership = get_post($membership_id);
        if (! $membership instanceof \WP_Post) {
            return [];
        }
        $context['membership'] = $membership->ID;
        $context['membership_name'] = $membership->post_name;
        $context['membership_title'] = $membership->post_title;
        $context['membership_url'] = get_permalink($membership_id);

        return $context;
    }

    /**
     * Is Plugin depended plugin is installed or not.
     *
     * @return bool
     */
    public function is_plugin_installed(): bool
    {
        return class_exists('LifterLMS');
    }
}

IntegrationsController::register(LifterLMS::class);
