import { describe, it, expect } from "vitest";
import { deleteMediaController } from "@/interface-adapters/controllers/delete-media.controller";
import { deleteMediaUseCase } from "@/application/use-cases/delete-media.use-case";
import { MockMediaRepository } from "@/infrastructure/repositories/media.repository.mock";
import { MediaNotFoundError } from "@/entities/errors/media";
import { InputParseError } from "@/entities/errors/common";
import { mediaFactory } from "@/__factories__/media.factory";

describe("deleteMediaController", () => {
  it("deletes media successfully", async () => {
    const repo = new MockMediaRepository();
    const seed = mediaFactory.build({ id: "m-1" });
    await repo._store(seed);

    const useCase = deleteMediaUseCase(repo);
    const controller = deleteMediaController(useCase);

    await expect(controller({ id: "m-1" })).resolves.toBeUndefined();
    const result = await repo.getMedia("m-1");
    expect(result).toBeUndefined();
  });

  it("throws InputParseError when id is missing", async () => {
    const repo = new MockMediaRepository();
    const useCase = deleteMediaUseCase(repo);
    const controller = deleteMediaController(useCase);

    await expect(controller({})).rejects.toThrow(InputParseError);
  });

  it("throws MediaNotFoundError when media does not exist", async () => {
    const repo = new MockMediaRepository();
    const useCase = deleteMediaUseCase(repo);
    const controller = deleteMediaController(useCase);

    await expect(controller({ id: "missing" })).rejects.toThrow(MediaNotFoundError);
  });
});
