<?php
declare(strict_types=1);
namespace Services;

use Repositories\BlogRepository;

final class BlogService
{
    public function __construct(private ?BlogRepository $repo = null) { $this->repo ??= new BlogRepository(); }
    public function list(array $filters): array { return $this->repo->all($filters); }
    public function detail(string $slug): ?array
    {
        $blog = $this->repo->findBySlug($slug);
        if (!$blog) return null;
        $blog['related_articles'] = $this->repo->related((int)$blog['id']);
        $blog['schema'] = ['@context' => 'https://schema.org', '@type' => 'BlogPosting', 'headline' => $blog['title'], 'description' => $blog['meta_description'], 'datePublished' => $blog['published_at']];
        return $blog;
    }
}
