<?php

declare(strict_types=1);

namespace Builder\Core\Foundation\Tables;

use Closure;

final class BulkAction
{
    private string $label;

    private ?string $icon = null;

    private ?Closure $handle = null;

    private ?string $confirm = null;

    private ?string $permission = null;

    private function __construct(private readonly string $key)
    {
        $this->label = $key;
    }

    public static function make(string $key): self
    {
        return new self($key);
    }

    public function label(string $label): self
    {
        $this->label = $label;

        return $this;
    }

    public function icon(string $icon): self
    {
        $this->icon = $icon;

        return $this;
    }

    public function handle(Closure $handle): self
    {
        $this->handle = $handle;

        return $this;
    }

    public function confirm(string $message): self
    {
        $this->confirm = $message;

        return $this;
    }

    public function permission(string $permission): self
    {
        $this->permission = $permission;

        return $this;
    }

    public function getKey(): string
    {
        return $this->key;
    }

    public function getLabel(): string
    {
        return $this->label;
    }

    public function getIcon(): ?string
    {
        return $this->icon;
    }

    public function getHandle(): ?Closure
    {
        return $this->handle;
    }

    public function getConfirm(): ?string
    {
        return $this->confirm;
    }

    public function getPermission(): ?string
    {
        return $this->permission;
    }

    /** @return array<string, mixed> */
    public function toArray(): array
    {
        return [
            'key' => $this->key,
            'label' => $this->label,
            'icon' => $this->icon,
            'confirm' => $this->confirm,
            'permission' => $this->permission,
        ];
    }
}
