<?php

declare(strict_types=1);

namespace App\Services\Sitemaps\Builders;

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

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

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

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

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

    protected function query(): Builder
    {
        return Artwork::query()
            ->public()
            ->published();
    }

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