<?php

namespace App\Filament\Resources\PreQuestionCandidateResource\Actions;

use Filament\Actions\BulkAction;
use Filament\Facades\Filament;
use Illuminate\Database\Eloquent\Collection;

class MarkAsNonQuestionsBulkAction extends BulkAction
{
    public function getName(): string
    {
        return 'mark_as_non_questions';
    }

    protected function setUp(): void
    {
        parent::setUp();

        $this->label('标记为非题目');

        $this->color('danger');

        $this->icon('heroicon-o-x-circle');

        $this->action(function (Collection $records) {
            $count = $records->count();

            foreach ($records as $record) {
                $record->update([
                    'is_question_candidate' => false,
                    'status' => 'rejected',
                ]);
            }

            Filament::notify('success', "成功将 {$count} 个候选题标记为非题目");
        });
    }
}
