import { TINNumber } from "./tin-number";

describe("TINNumber", () => {
  it("debería crear un TINNumber válido", () => {
    const result = TINNumber.create("12345");
    expect(result.isSuccess).toBe(true);
    expect(result.data.getValue()).toBe("12345");
  });

  it("debería fallar si el valor es demasiado corto", () => {
    const result = TINNumber.create("1");
    expect(result.isFailure).toBe(true);
    expect(result.error?.message).toBe("TIN must be at least 2 characters long");
  });

  it("debería fallar si el valor es demasiado largo", () => {
    const result = TINNumber.create("12345678901");
    expect(result.isFailure).toBe(true);
    expect(result.error?.message).toBe("TIN must be at most 10 characters long");
  });

  it("debería devolver None cuando el valor es nulo o vacío en createNullable", () => {
    const result = TINNumber.createNullable("");
    expect(result.isSuccess).toBe(true);
    expect(result.data.isNone()).toBe(true);
  });

  it("debería devolver Some cuando el valor es válido en createNullable", () => {
    const result = TINNumber.createNullable("6789");
    expect(result.isSuccess).toBe(true);
    expect(result.data.isSome()).toBe(true);
    expect(result.data.unwrap()?.toString()).toBe("6789");
  });

  it("debería devolver el valor correcto en toString()", () => {
    const result = TINNumber.create("ABC123");
    expect(result.isSuccess).toBe(true);
    expect(result.data.toString()).toBe("ABC123");
  });
});
