<?php

declare(strict_types=1);

namespace ACA\RankMath\ColumnFactory\Post;

use AC\Formatter\BeforeAfter;
use AC\Formatter\Post\Meta;
use AC\FormatterCollection;
use AC\Setting\Config;
use ACA\RankMath\ColumnFactory\GroupTrait;
use ACP;
use ACP\ConditionalFormat\ConditionalFormatTrait;
use ACP\Metric;
use ACP\Sorting\Type\DataType;

final class Score extends ACP\Column\AdvancedColumnFactory
{
    use ConditionalFormatTrait;
    use GroupTrait;

    private const META_KEY = 'rank_math_seo_score';

    public function get_column_type(): string
    {
        return 'column-rankmath-score';
    }

    public function get_label(): string
    {
        return __('SEO Score', 'codepress-admin-columns');
    }

    protected function get_formatters(Config $config): FormatterCollection
    {
        return parent::get_formatters($config)
            ->prepend(new Meta(self::META_KEY))
            ->add(new BeforeAfter('', ' / 100'));
    }

    protected function get_search(Config $config): ?ACP\Search\Comparison
    {
        return new ACP\Search\Comparison\Meta\Number(self::META_KEY);
    }

    protected function get_sorting(Config $config): ?ACP\Sorting\Model\QueryBindings
    {
        return new ACP\Sorting\Model\Post\Meta(self::META_KEY, new DataType(DataType::NUMERIC));
    }

    protected function get_export(Config $config): ?FormatterCollection
    {
        return FormatterCollection::from_formatter(new Meta(self::META_KEY));
    }

    protected function get_metric(Config $config): ?Metric\Config
    {
        return Metric\Config\Meta\Numeric::for_post(self::META_KEY);
    }

}
