<?php

namespace App\Http\Controllers\Admin\System;

use App\Enums\ActivityEventLabel;
use App\Http\Controllers\Concerns\ParsesDataTableQuery;
use App\Http\Controllers\Controller;
use App\Services\System\ActivityLogService;
use App\Support\ActivityLog\ModelLabel;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;

class ActivityLogController extends Controller
{
    use ParsesDataTableQuery;

    public function __construct(
        private readonly ActivityLogService $activityLogService,
    ) {}

    public function index(Request $request): Response
    {
        $tableQuery = $this->parseDataTableQuery($request);
        $event = $request->string('event')->toString();
        $subjectType = $request->string('subject_type')->toString();

        return Inertia::render('admin/system/activity-logs/Index', [
            'activityLogs' => $this->activityLogService->paginateForIndex($tableQuery, $event, $subjectType),
            'filters' => $this->dataTableFilters($tableQuery, [
                'event' => $event,
                'subject_type' => $subjectType,
            ]),
            'eventOptions' => ActivityEventLabel::selectOptions(),
            'subjectOptions' => ModelLabel::selectOptions(),
        ]);
    }
}
