import { describe, it, expect } from "vitest";
import { adminOperationsRouter } from "./adminOperations.ts";

describe("Admin Operations Router", () => {
  describe("Router Structure", () => {
    it("should be defined", () => {
      expect(adminOperationsRouter).toBeDefined();
    });

    it("should have procedures defined", () => {
      expect(adminOperationsRouter._def).toBeDefined();
      expect(adminOperationsRouter._def.procedures).toBeDefined();
    });
  });

  describe("Games Management Procedures", () => {
    it("should have listGames procedure", () => {
      const procedures = adminOperationsRouter._def.procedures;
      expect(procedures).toHaveProperty("listGames");
    });

    it("should have toggleGameStatus procedure", () => {
      const procedures = adminOperationsRouter._def.procedures;
      expect(procedures).toHaveProperty("toggleGameStatus");
    });

    it("should have bulkToggleGames procedure", () => {
      const procedures = adminOperationsRouter._def.procedures;
      expect(procedures).toHaveProperty("bulkToggleGames");
    });
  });

  describe("Users Management Procedures", () => {
    it("should have listUsers procedure", () => {
      const procedures = adminOperationsRouter._def.procedures;
      expect(procedures).toHaveProperty("listUsers");
    });

    it("should have suspendUser procedure", () => {
      const procedures = adminOperationsRouter._def.procedures;
      expect(procedures).toHaveProperty("suspendUser");
    });

    it("should have promoteToVIP procedure", () => {
      const procedures = adminOperationsRouter._def.procedures;
      expect(procedures).toHaveProperty("promoteToVIP");
    });
  });

  describe("KYC Management Procedures", () => {
    it("should have listPendingKYC procedure", () => {
      const procedures = adminOperationsRouter._def.procedures;
      expect(procedures).toHaveProperty("listPendingKYC");
    });

    it("should have approveKYC procedure", () => {
      const procedures = adminOperationsRouter._def.procedures;
      expect(procedures).toHaveProperty("approveKYC");
    });

    it("should have rejectKYC procedure", () => {
      const procedures = adminOperationsRouter._def.procedures;
      expect(procedures).toHaveProperty("rejectKYC");
    });
  });

  describe("Audit Logs Procedures", () => {
    it("should have listAuditLogs procedure", () => {
      const procedures = adminOperationsRouter._def.procedures;
      expect(procedures).toHaveProperty("listAuditLogs");
    });

    it("should have exportAuditLogs procedure", () => {
      const procedures = adminOperationsRouter._def.procedures;
      expect(procedures).toHaveProperty("exportAuditLogs");
    });
  });

  describe("Procedure Types", () => {
    it("all procedures should be properly typed", () => {
      const procedures = adminOperationsRouter._def.procedures;
      
      // Verify all procedures are defined
      const expectedProcedures = [
        "listGames",
        "toggleGameStatus",
        "bulkToggleGames",
        "listUsers",
        "suspendUser",
        "promoteToVIP",
        "listPendingKYC",
        "approveKYC",
        "rejectKYC",
        "listAuditLogs",
        "exportAuditLogs",
      ];

      expectedProcedures.forEach(proc => {
        expect(procedures).toHaveProperty(proc);
        expect(procedures[proc as keyof typeof procedures]).toBeDefined();
      });
    });
  });

  describe("Admin Authorization", () => {
    it("should enforce admin role requirement", () => {
      // The adminProcedure middleware should be applied to all procedures
      const procedures = adminOperationsRouter._def.procedures;
      
      // All procedures should be protected (not public)
      Object.values(procedures).forEach(proc => {
        expect(proc).toBeDefined();
        // Procedures should have middleware applied
        expect(proc._def).toBeDefined();
      });
    });
  });
});
