<?php

namespace App\DataTables;

use App\Repositories\QueueRepository;
use Yajra\DataTables\Services\DataTable;

class FailedJobsDataTable extends DataTable
{
    protected QueueRepository $repo;

    public function __construct(QueueRepository $repo)
    {
        $this->repo = $repo;
    }

    public function ajax()
    {
        return datatables()->of($this->repo->failedQuery())
            ->addColumn('actions', function ($row) {
                return view('admin.queue._failed_actions', compact('row'))->render();
            })
            ->rawColumns(['actions'])
            ->make(true);
    }

    public function query()
    {
        return $this->repo->failedQuery();
    }

    public function html()
    {
        return $this->builder()
            ->setTableId('failed-jobs-table')
            ->columns([
                'id', 'uuid', 'connection', 'queue', 'failed_at',
            ])
            ->minifiedAjax(route('queue.failed.data'))
            ->orderBy(0);
    }

    protected function getColumns()
    {
        return [
            'id', 'uuid', 'connection', 'queue', 'failed_at',
        ];
    }
}
