<?php

namespace App\Services\Instagram;

use App\Models\InstagramNotificationType;
use Facebook\WebDriver\Remote\RemoteWebElement;

class NotificationTypeDetector
{
    /**
     * Detects the Instagram notification type from the DOM.
     *
     * @param string $descriptionText The text content of the notification description.
     * @return InstagramNotificationType
     */
    public static function detectType(string $descriptionText): InstagramNotificationType
    {
        $descriptionText = trim($descriptionText); // Remove leading/trailing whitespace

        // Prioritize exact matches for reliability
        if (strpos($descriptionText, 'liked') !== false) {
            return InstagramNotificationType::LIKE;
        } elseif (strpos($descriptionText, 'commented') !== false) {
            return InstagramNotificationType::COMMENT;
        } elseif (strpos($descriptionText, 'following you') !== false) {
            return InstagramNotificationType::FOLLOW;
        } elseif (strpos($descriptionText, 'message') !== false) {
            return InstagramNotificationType::MESSAGE;
        } elseif (strpos($descriptionText, 'congratulations') !== false || strpos($descriptionText, 'update') !== false) {
            return InstagramNotificationType::SYSTEM;
        } elseif (strpos($descriptionText, 'mention') !== false) {
            return InstagramNotificationType::MENTION;
        }

        return InstagramNotificationType::OTHER;
    }
}
