<?php

namespace App\Helpers;

use App\Models\TicketAssignmentModel;
use App\Models\TicketModel;

class TicketMapper
{
  public function toTicket(array $row): TicketModel
  {
    return new TicketModel(
      id: (int) $row['id_ticket'],

      userId: (int) $row['id_user'],
      namaUser: $row['nama'],

      kategoriId: (int) $row['id_kategori'],
      namaKategori: $row['nama_kategori'],

      prioritasId: (int) $row['id_prioritas'] ?? 0,
      namaPrioritas: $row['nama_prioritas'] ?? '',

      slaId: (int) $row['id_sla'] ?? 0,
      namaSla: $row['nama_sla'] ?? '',

      statusId: (int) $row['id_status'],
      namaStatus: $row['nama_status'],

      judul: $row['judul'],
      deskripsi: $row['deskripsi'],

      tanggalDibuat: $row['tanggal_dibuat'],
      tanggalUpdate: $row['tanggal_update'],
      deadline: $row['deadline'],

      isClosed: (bool) $row['is_closed'],

      nomorTiket: $row['nomor_tiket']
    );
  }

  public function toTicketAssignment(array $row): TicketAssignmentModel
  {
    return new TicketAssignmentModel(
      id: (int)$row['id_assignment'],
      ticketId: (int)$row['id_ticket'],
      teknisiId: (int)$row['id_teknisi'],
      statusId: (int)$row['id_status'],
      tanggalDitugaskan: $row['tanggal_ditugaskan'],
      tanggalSelesai: $row['tanggal_selesai'],
      statusPenugasan: $row['status_penugasan'],
      catatan: $row['catatan']
    );
  }
}
