<?php

namespace App\Services\Concerns;

use App\Services\Media\MediaService;
use Spatie\MediaLibrary\HasMedia;

/**
 * @property-read MediaService $mediaService
 */
trait SyncsPhotos
{
    protected function syncPhotos(
        HasMedia $model,
        array $validated,
        int $maxPhotos = 1,
        bool $required = true,
        string $collection = 'photos',
        ?string $errorKey = null,
    ): void {
        $this->mediaService->syncCollection(
            $model,
            $collection,
            $validated['photos'] ?? null,
            $validated['remove_media_ids'] ?? null,
            $maxPhotos,
            required: $required,
            errorKey: $errorKey ?? $collection,
            s3Keys: $validated['s3_keys'] ?? null,
        );
    }
}
