<?php

namespace App\Http\Controllers;

use App\Http\Requests\VentumStoreRequest;
use App\Http\Requests\VentumUpdateRequest;
use App\Http\Resources\VentumCollection;
use App\Http\Resources\VentumResource;
use App\Models\Venta;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class VentaController extends Controller
{
    public function index(Request $request): VentumCollection
    {
        $venta = Ventum::all();

        return new VentumCollection($venta);
    }

    public function store(VentumStoreRequest $request): VentumResource
    {
        $ventum = Ventum::create($request->validated());

        return new VentumResource($ventum);
    }

    public function show(Request $request, Ventum $ventum): VentumResource
    {
        return new VentumResource($ventum);
    }

    public function update(VentumUpdateRequest $request, Ventum $ventum): VentumResource
    {
        $ventum->update($request->validated());

        return new VentumResource($ventum);
    }

    public function destroy(Request $request, Ventum $ventum): Response
    {
        $ventum->delete();

        return response()->noContent();
    }

    public function imprimirRecibo(Venta $venta)
    {
        return view('recibos.ticket', compact('venta'));
    }
}
