<?php

namespace App\Domains\Ticket\Controllers;

use App\Domains\Tenant\Models\Tenant;
use App\Domains\Ticket\Models\Ticket;
use App\Domains\Ticket\Resources\TicketResource;
use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class TicketController extends Controller
{
    public function index(Request $request, Tenant $tenant): JsonResponse
    {
        $tickets = Ticket::query()
            ->where('tenant_code', $tenant->codigo)
            ->where('user_id', $request->user()->getKey())
            ->orderByDesc('id')
            ->get();

        return TicketResource::collection($tickets)->response();
    }
}
