<?php

namespace App\Services\Ticket;

use App\Models\TicketIncidentType;

class TicketIncidentTypeService
{
    public function getAll()
    {
        return TicketIncidentType::orderBy('name')->get();
    }

    public function create(array $data): TicketIncidentType
    {
        return TicketIncidentType::create([
            'name' => $data['name'],
            'is_active' => $data['is_active'] ?? true
        ]);
    }

    public function update(
        TicketIncidentType $ticketIncidentType,
        array $data
    ): TicketIncidentType {
        $ticketIncidentType->update([
            'name' => $data['name'],
            'is_active' => $data['is_active']
        ]);

        return $ticketIncidentType->fresh();
    }

    public function delete(TicketIncidentType $ticketIncidentType): void
    {
        $ticketIncidentType->delete();
    }
}