import { describe, test, expect } from "bun:test";
import { UnifiSiteController } from "../../../src/controllers/UnifiSiteController";
import { buildMockUnifiSite } from "../../setup";

describe("UnifiSiteController", () => {
  describe("constructor", () => {
    test("sets all properties from site data", () => {
      const ctrl = new UnifiSiteController(buildMockUnifiSite());
      expect(ctrl.id).toBe("usite-1");
      expect(ctrl.name).toBe("Main Office");
      expect(ctrl.siteId).toBe("default");
      expect(ctrl.companyId).toBeNull();
    });

    test("accepts non-null companyId", () => {
      const ctrl = new UnifiSiteController(
        buildMockUnifiSite({ companyId: "company-1" }),
      );
      expect(ctrl.companyId).toBe("company-1");
    });
  });

  describe("toJson()", () => {
    test("returns all properties", () => {
      const ctrl = new UnifiSiteController(
        buildMockUnifiSite({ companyId: "comp-abc" }),
      );
      const json = ctrl.toJson();
      expect(json).toEqual({
        id: "usite-1",
        name: "Main Office",
        siteId: "default",
        companyId: "comp-abc",
      });
    });

    test("companyId is null when unlinked", () => {
      const ctrl = new UnifiSiteController(buildMockUnifiSite());
      const json = ctrl.toJson();
      expect(json.companyId).toBeNull();
    });
  });
});
