import { describe, it, expect } from "vitest";
import { listMediaController } from "@/interface-adapters/controllers/list-media.controller";
import { listMediaUseCase } from "@/application/use-cases/list-media.use-case";
import { MockMediaRepository } from "@/infrastructure/repositories/media.repository.mock";
import { mediaFactory } from "@/__factories__/media.factory";

describe("listMediaController", () => {
  it("returns empty array when no media exists", async () => {
    const repo = new MockMediaRepository();
    const useCase = listMediaUseCase(repo);
    const controller = listMediaController(useCase);

    const result = await controller({});
    expect(result).toHaveLength(0);
  });

  it("returns all media", async () => {
    const repo = new MockMediaRepository();
    await repo._store(mediaFactory.build());
    await repo._store(mediaFactory.build());

    const useCase = listMediaUseCase(repo);
    const controller = listMediaController(useCase);

    const result = await controller({});
    expect(result).toHaveLength(2);
  });

  it("passes limit and offset to use case", async () => {
    const repo = new MockMediaRepository();
    for (let i = 0; i < 5; i++) {
      await repo._store(mediaFactory.build());
    }

    const useCase = listMediaUseCase(repo);
    const controller = listMediaController(useCase);

    const result = await controller({ limit: 2, offset: 1 });
    expect(result).toHaveLength(2);
  });
});
