<?php

// Silence may be golden, but sometimes words paint the canvas of understanding.
namespace Linksy\SearchAndReplace\Plugli\Linksy\Common\Helpers\Keywords\Traits;

use Linksy\SearchAndReplace\Plugli\Standard\Helpers\Arr;
trait SEOPlugins
{
    private function extract_rank_math_keywords($record)
    {
        return [$record->post_id, Arr::split($record->meta_value)];
    }
    private function extract_yoast_keywords($record)
    {
        return [$record->post_id, Arr::split($record->meta_value)];
    }
    private function extract_seopress_keywords($record)
    {
        return [$record->post_id, Arr::split($record->meta_value)];
    }
    private function extract_boldgrid_easy_keywords($record)
    {
        return [$record->post_id, Arr::split($record->meta_value)];
    }
    private function extract_squirrly_keywords($record)
    {
        return [unserialize($record->post)['ID'], Arr::split(unserialize($record->seo)['keywords'])];
    }
    private function extract_aio_keywords($record)
    {
        $keywords = [];
        if (!empty($record->keyphrases)) {
            $json_data = json_decode($record->keyphrases);
            if (!empty($json_data->focus) && !empty($json_data->focus->keyphrase)) {
                $keywords[] = $json_data->focus->keyphrase;
            }
            if (!empty($json_data->additional)) {
                foreach ($json_data->additional as $keyword) {
                    $keywords[] = $keyword->keyphrase;
                }
            }
        }
        return [$record->post_id, $keywords];
    }
    private function extract_wpsso_core_keywords($record)
    {
        $metadata = unserialize($record->meta_value);
        if (!empty($metadata['schema_keywords_csv'])) {
            return [$record->post_id, Arr::split($metadata['schema_keywords_csv'], ', ')];
        }
        return [];
    }
    private function extract_smartcrawl_keywords($record)
    {
        return [$record->post_id, Arr::split($record->meta_value)];
    }
    private function extract_seo_framework_keywords($record)
    {
        $keyword_data = unserialize(unserialize($record->meta_value));
        if (empty($keyword_data['focus']) || empty($keyword_data['focus']['kw'])) {
            return [];
        }
        $keywords = [];
        foreach ($keyword_data['focus']['kw'] as $kw) {
            if (!empty($kw['keyword'])) {
                $keywords[] = $kw['keyword'];
            }
        }
        return [$record->post_id, $keywords];
    }
}
