import { UtcDate } from "../utc-date";

describe("UtcDate Value Object con Zod y Result", () => {
  test("Debe crear una instancia con fecha y hora en UTC", () => {
    const result = UtcDate.createFromISO("2025-01-06T19:36:18Z");
    expect(result.isSuccess).toBe(true);
    expect(result.data?.toISOString()).toBe("2025-01-06T19:36:18.000Z");
    expect(result.data?.toDateString()).toBe("2025-01-06");
  });

  test("Debe crear una instancia con solo fecha (sin hora)", () => {
    const result = UtcDate.createFromISO("2020-11-12");
    expect(result.isSuccess).toBe(true);
    expect(result.data?.toISOString()).toBe("2020-11-12T00:00:00.000Z"); // Normalizado con 00:00 UTC
    expect(result.data?.toDateString()).toBe("2020-11-12");
  });

  test("Debe devolver un Result.fail para formatos inválidos", () => {
    expect(UtcDate.createFromISO("2020-07-32").isFailure).toBe(true);
    expect(UtcDate.createFromISO("invalid-date").isFailure).toBe(true);
    expect(UtcDate.createFromISO("2020/11/12").isFailure).toBe(true);
  });

  test("Debe comparar correctamente dos fechas idénticas", () => {
    const date1 = UtcDate.createFromISO("2023-12-31T23:59:59Z").data!;
    const date2 = UtcDate.createFromISO("2023-12-31T23:59:59Z").data!;
    expect(date1.equals(date2)).toBe(true);
  });

  test("Debe comparar correctamente dos fechas diferentes", () => {
    const date1 = UtcDate.createFromISO("2023-12-31T23:59:59Z").data!;
    const date2 = UtcDate.createFromISO("2023-12-30T23:59:59Z").data!;
    expect(date1.equals(date2)).toBe(false);
  });

  test("Debe manejar fechas sin hora correctamente en equals", () => {
    const date1 = UtcDate.createFromISO("2020-11-12").data!;
    const date2 = UtcDate.createFromISO("2020-11-12T00:00:00Z").data!;
    expect(date1.equals(date2)).toBe(true);
  });
});
