<?php

namespace App\Http\Controllers;

use App\Http\Requests\TicketRequest;
use App\Services\TicketService;
use App\Traits\HasResponse;
use Illuminate\Http\Request;

class TicketController extends Controller
{
    use HasResponse;

    /** @var TicketService */
    private $ticketService;

    public function __construct(TicketService $ticketService)
    {
        $this->ticketService = $ticketService;
    }

    public function list(Request $request)
    {
        $withPagination = $this->validatePagination($request->only('perPage', 'page'));
        return $this->ticketService->list($withPagination);
    }

    public function listRoute(Request $request)
    {
        $withPagination = $this->validatePagination($request->only('perPage', 'page'));
        return $this->ticketService->listRoute($withPagination);
    }

    public function listRoutePDF($id)
    {
       return $this->ticketService->generateRoutePDF($id);
    }

    public function listDispatchPDF($idroute, $id)
    {
       return $this->ticketService->generateDispatchPDF($idroute, $id);
    }

    public function salesBook(Request $request)
    {
        $withPagination = $this->validatePagination($request->only('perPage', 'page'));
        return $this->ticketService->salesBook($withPagination);
    }

    public function register(TicketRequest $request)
    {
        return $this->ticketService->register($request->validated());
    }

    public function registerRelation(Request $request)
    {
        return $this->ticketService->registerRelation($request->all());
    }

    public function delete($id)
    {
        return $this->ticketService->delete($id);
    }

    public function generateDocument(Request $request)
    {
        return $this->ticketService->generateDocument($request->all());
    }

    public function generateRoute(Request $request)
    {
        return $this->ticketService->generateRoute($request->all());
    }

    public function confirmTicket($id, Request $request)
    {
        return $this->ticketService->confirmTicket($id, $request->all());
    }

    public function changeStatus($id, Request $request)
    {
        return $this->ticketService->changeStatus($id, $request->all());
    }
}
