import { describe, expect, it } from "vitest";
import { FLOCK_LIMITS } from "@/lib/constants/flock-limits";
import { isFlockRpaEnabled } from "@/lib/flock/env";

describe("flock limits & env", () => {
  it("硬限与 PRD §14.3 一致", () => {
    expect(FLOCK_LIMITS.palletCount).toEqual({ min: 4, max: 20 });
    expect(FLOCK_LIMITS.totalWeightLbMax).toBe(45_000);
    expect(FLOCK_LIMITS.dimIn).toEqual({
      lengthMax: 636,
      widthMax: 102,
      heightMax: 108,
      min: 1,
    });
  });

  it("Mock 模式下视为启用", () => {
    const prevMock = process.env.RPA_MOCK_MODE;
    const prevEnabled = process.env.FLOCK_RPA_ENABLED;
    const prevNode = process.env.NODE_ENV;
    process.env.RPA_MOCK_MODE = "true";
    process.env.FLOCK_RPA_ENABLED = "false";
    process.env.NODE_ENV = "production";
    expect(isFlockRpaEnabled()).toBe(true);
    process.env.RPA_MOCK_MODE = prevMock;
    process.env.FLOCK_RPA_ENABLED = prevEnabled;
    process.env.NODE_ENV = prevNode;
  });

  it("development 且未显式关闭时默认启用", () => {
    const prevEnabled = process.env.FLOCK_RPA_ENABLED;
    const prevNode = process.env.NODE_ENV;
    delete process.env.FLOCK_RPA_ENABLED;
    process.env.NODE_ENV = "development";
    expect(isFlockRpaEnabled()).toBe(true);
    process.env.FLOCK_RPA_ENABLED = "false";
    expect(isFlockRpaEnabled()).toBe(false);
    process.env.FLOCK_RPA_ENABLED = prevEnabled;
    process.env.NODE_ENV = prevNode;
  });
});
