<?php

declare(strict_types=1);

namespace App\Console\Commands;

use Illuminate\Console\Command;

final class CheckArtworkUserIdsCommand extends Command
{
    protected $signature = 'artworks:check-user-ids
                            {--chunk=1000 : Number of artworks to process per chunk}
                            {--show-missing=25 : Maximum number of missing references to print}
                            {--artwork-id= : Only check this specific artwork ID}
                            {--json : Output the summary as JSON}';

    protected $description = 'Check whether every artworks.user_id exists in the users table.';

    public function handle(): int
    {
        $options = [
            '--chunk' => (string) max(1, (int) $this->option('chunk')),
            '--show-missing' => (string) max(0, (int) $this->option('show-missing')),
        ];

        if ($this->option('artwork-id') !== null) {
            $options['--artwork-id'] = (string) (int) $this->option('artwork-id');
        }

        if ((bool) $this->option('json')) {
            $options['--json'] = true;
        }

        return $this->call('artworks:check-user-refs', $options);
    }
}