import { describe, it, expectTypeOf } from "vitest";
import type {
  IRateLimit,
  RateLimitBudget,
  RateLimitDecision,
} from "@/rate-limit/rate-limit.interface";

describe("rate-limit types", () => {
  it("RateLimitBudget has the expected shape", () => {
    expectTypeOf<RateLimitBudget>().toMatchTypeOf<{
      name: string;
      window: string;
      budget: number;
    }>();
  });

  it("RateLimitDecision has the expected shape", () => {
    expectTypeOf<RateLimitDecision>().toMatchTypeOf<{
      allowed: boolean;
      remaining: number;
      resetAt: Date;
    }>();
  });

  it("IRateLimit.consume returns Promise<RateLimitDecision>", () => {
    expectTypeOf<
      IRateLimit["consume"]
    >().returns.resolves.toEqualTypeOf<RateLimitDecision>();
  });

  it("IRateLimit.consume accepts optional weight", () => {
    type ConsumeParams = Parameters<IRateLimit["consume"]>;
    expectTypeOf<ConsumeParams[0]>().toEqualTypeOf<string>();
    expectTypeOf<ConsumeParams[1]>().toEqualTypeOf<string>();
    expectTypeOf<ConsumeParams[2]>().toEqualTypeOf<number | undefined>();
  });

  it("IRateLimit.reset returns Promise<void>", () => {
    expectTypeOf<IRateLimit["reset"]>().returns.resolves.toEqualTypeOf<void>();
  });
});
