import { describe, test, expect } from "bun:test";
import { ValueType } from "../../src/modules/credentials/credentialTypeDefs";
import type { CredentialTypeField } from "../../src/modules/credentials/credentialTypeDefs";

describe("credentialTypeDefs", () => {
  describe("ValueType enum", () => {
    test("has expected values", () => {
      expect(ValueType.PLAIN_TEXT as string).toBe("plain_text");
      expect(ValueType.LICENSE_KEY as string).toBe("license_key");
      expect(ValueType.IP_ADDRESS as string).toBe("ip_address");
      expect(ValueType.GENERIC_SECRET as string).toBe("generic_secret");
      expect(ValueType.BITLOCKER_KEY as string).toBe("bitlocker_key");
      expect(ValueType.PASSWORD as string).toBe("password");
      expect(ValueType.MULTI_CREDENTIAL as string).toBe("multi_credential");
    });

    test("has exactly 7 members", () => {
      const values = Object.values(ValueType);
      expect(values).toHaveLength(7);
    });
  });

  describe("CredentialTypeField type", () => {
    test("valid field shape satisfies interface", () => {
      const field: CredentialTypeField = {
        id: "test",
        name: "Test Field",
        required: true,
        secure: false,
        valueType: ValueType.PLAIN_TEXT,
      };
      expect(field.id).toBe("test");
      expect(field.subFields).toBeUndefined();
    });

    test("field with subFields satisfies interface", () => {
      const field: CredentialTypeField = {
        id: "multi",
        name: "Multi",
        required: false,
        secure: false,
        valueType: ValueType.MULTI_CREDENTIAL,
        subFields: [
          {
            id: "sub1",
            name: "Sub 1",
            required: true,
            secure: false,
            valueType: ValueType.PLAIN_TEXT,
          },
        ],
      };
      expect(field.subFields).toHaveLength(1);
    });
  });
});
