import { InvoiceStatus } from "./invoice-status";

// Pruebas para InvoiceStatus
describe("InvoiceStatus", () => {
  test("Debe crear estados válidos", () => {
    const result1 = InvoiceStatus.create("borrador");
    const result2 = InvoiceStatus.create("enviada");
    const result3 = InvoiceStatus.create("cerrada");

    expect(result1.isSuccess).toBe(true);
    expect(result1.data.getValue()).toBe("borrador");
    expect(result1.data.toString()).toBe("borrador");

    expect(result2.isSuccess).toBe(true);
    expect(result2.data.getValue()).toBe("enviada");
    expect(result2.data.toString()).toBe("enviada");

    expect(result3.isSuccess).toBe(true);
    expect(result3.data.getValue()).toBe("cerrada");
    expect(result3.data.toString()).toBe("cerrada");
  });

  test("Debe lanzar error al crear un estado inválido", () => {
    const result = InvoiceStatus.create("inexistente");
    expect(result.isFailure).toBe(true);
  });

  test("Debe permitir transiciones válidas #1", () => {
    const result = InvoiceStatus.create("borrador");
    expect(result.isSuccess).toBe(true);
    expect(result.data.canTransitionTo("enviada")).toBe(true);
  });

  test("Debe permitir transiciones válidas #2", () => {
    const result = InvoiceStatus.create("borrador");
    expect(result.isSuccess).toBe(true);

    const new_state = result.data.transitionTo("enviada");
    expect(new_state.isSuccess).toBe(true);
    expect(new_state.data.toString()).toBe("enviada");
  });

  test("Debe impedir transiciones inválidas", () => {
    const result = InvoiceStatus.create("cerrada");
    expect(result.isSuccess).toBe(true);
    expect(result.data.canTransitionTo("enviada")).toBe(false);
  });

  test("Debe lanzar error al intentar transición inválida", () => {
    const result = InvoiceStatus.create("borrador");
    expect(result.isSuccess).toBe(true);
    const new_state = result.data.transitionTo("cerrada");
    expect(new_state.isSuccess).toBe(false);
    expect(new_state.error.message).toContain("Transición no permitida de borrador a cerrada");
  });
});
