<?php

namespace App\Domains\Ticket\Controllers\Scanner;

use App\Domains\Auth\Models\User;
use App\Domains\Ticket\Requests\ScannerTicketIndexRequest;
use App\Domains\Ticket\Resources\Scanner\ScannedTicketResource;
use App\Domains\Ticket\Resources\TicketResource;
use App\Domains\Ticket\Services\ScannerTicketService;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;

class TicketController extends Controller
{
    public function __construct(private readonly ScannerTicketService $ticketService) {}

    public function index(ScannerTicketIndexRequest $request): AnonymousResourceCollection
    {
        /** @var User $scanner */
        $scanner = $request->user();

        return ScannedTicketResource::collection(
            $this->ticketService->scannedBy($scanner, $request->validated())
        );
    }

    public function show(Request $request, string $ticketUuid): TicketResource
    {
        /** @var User $scanner */
        $scanner = $request->user();

        return TicketResource::make(
            $this->ticketService->detail($scanner, $ticketUuid)
        );
    }

    public function scan(Request $request, string $ticketUuid): TicketResource
    {
        /** @var User $scanner */
        $scanner = $request->user();

        return TicketResource::make(
            $this->ticketService->scan($scanner, $ticketUuid)
        );
    }
}
