<?php

namespace App\Http\Controllers\Ticket;

use App\Http\Controllers\ApiController;
use App\Http\Requests\TicketType\IndexTicketTypeRequest;
use App\Http\Requests\TicketType\StoreTicketTypeRequest;
use App\Http\Requests\TicketType\UpdateTicketTypeRequest;
use App\Http\Resources\TicketType\TicketTypeResource;
use App\Models\TicketType;
use App\Services\Ticket\TicketTypeService;

class TicketTypeController extends ApiController
{
    public function __construct(
        protected TicketTypeService $service
    ) {}

    public function index(IndexTicketTypeRequest $request)
    {
        $data = $this->service->list(
            $request->validated()
        );

        return $this->successPaginated(
            $data,
            TicketTypeResource::class,
            'Data Ticket Type berhasil diambil'
        );
    }

    public function store(StoreTicketTypeRequest $request)
    {
        $data = $this->service->create(
            $request->validated()
        );

        return $this->created(
            new TicketTypeResource($data),
            'Ticket Type berhasil dibuat'
        );
    }

    public function show(TicketType $ticket_type)
    {
        return $this->success(
            new TicketTypeResource($ticket_type),
            'Detail Ticket Type berhasil diambil'
        );
    }

    public function update(
        UpdateTicketTypeRequest $request,
        TicketType $ticket_type
    ) {
        $data = $this->service->update(
            $ticket_type,
            $request->validated()
        );

        return $this->updated(
            new TicketTypeResource($data),
            'Ticket Type berhasil diupdate'
        );
    }

    public function destroy(TicketType $ticket_type)
    {
        $this->service->delete($ticket_type);

        return $this->deleted(
            'Ticket Type berhasil dihapus'
        );
    }
}
