import { describe, expect, it } from "vitest";
import { mapTicketFromServer, mapTicketWithDetailsFromServer } from "@/lib/mappers/ticket";

describe("ticket mappers", () => {
  it("converte ticket básico (epoch -> Date)", () => {
    const now = Date.now();
    const ui = mapTicketFromServer({
      id: "t1",
      reference: 1,
      tenantId: "tenant",
      subject: "Teste",
      status: "OPEN",
      priority: "MEDIUM",
      channel: "EMAIL",
      queue: null,
      requester: { id: "u1", name: "Ana", email: "a@a.com", teams: [] },
      assignee: null,
      updatedAt: now,
      createdAt: now,
      tags: [],
      lastTimelineEntry: null,
    });
    expect(ui.createdAt).toBeInstanceOf(Date);
    expect(ui.updatedAt).toBeInstanceOf(Date);
    expect(ui.lastTimelineEntry).toBeUndefined();
    expect(ui.status).toBe("AWAITING_ATTENDANCE");
  });

  it("converte ticket com detalhes", () => {
    const now = Date.now();
    const ui = mapTicketWithDetailsFromServer({
      id: "t1",
      reference: 1,
      tenantId: "tenant",
      subject: "Teste",
      status: "OPEN",
      priority: "MEDIUM",
      channel: "EMAIL",
      queue: "Chamados",
      requester: { id: "u1", name: "Ana", email: "a@a.com", teams: [] },
      assignee: { id: "u2", name: "Bruno", email: "b@b.com", teams: [] },
      updatedAt: now,
      createdAt: now,
      tags: [],
      lastTimelineEntry: null,
      timeline: [{ id: "e1", type: "CREATED", createdAt: now }],
      comments: [{ id: "c1", author: { id: "u1", name: "Ana", email: "a@a.com", teams: [] }, visibility: "PUBLIC", body: "Oi", createdAt: now, updatedAt: now }],
    });
    expect(ui.timeline[0]!.createdAt).toBeInstanceOf(Date);
    expect(ui.comments[0]!.createdAt).toBeInstanceOf(Date);
    expect(ui.status).toBe("AWAITING_ATTENDANCE");
  });
});
