<?php

declare(strict_types=1);

namespace App\Services\Sitemaps\Builders;

use App\Models\Story;
use App\Services\Sitemaps\SitemapUrl;
use App\Services\Sitemaps\SitemapUrlBuilder;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

final class StoriesSitemapBuilder extends AbstractIdShardableSitemapBuilder
{
    public function __construct(private readonly SitemapUrlBuilder $urls)
    {
    }

    public function name(): string
    {
        return 'stories';
    }

    protected function shardConfigKey(): string
    {
        return 'stories';
    }

    protected function mapRecord(Model $record): ?SitemapUrl
    {
        return $this->urls->story($record);
    }

    protected function query(): Builder
    {
        return Story::query()
            ->published()
            ->orderBy('id');
    }

    protected function qualifiedIdColumn(): string
    {
        return 'stories.id';
    }
}