<?php

declare(strict_types=1);

namespace App\Services\Sitemaps\Builders;

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

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

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

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

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

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

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