import { beforeEach, describe, expect, it } from "vitest";
import { marketingPagesContainer } from "../src/di/container";
import { MARKETING_PAGES_SYMBOLS } from "../src/di/symbols";
import { MockPagesRepository } from "../src/infrastructure/repositories/pages.repository.mock";
import { MockSiteSettingsRepository } from "../src/infrastructure/repositories/site-settings.repository.mock";
import type { IPagesRepository } from "../src/application/repositories/pages.repository.interface";
import type { ISiteSettingsRepository } from "../src/application/repositories/site-settings.repository.interface";
import { marketingPagesRouter } from "../src/integrations/api/router";

describe("marketing-pages feature: page-by-slug end-to-end", () => {
  beforeEach(() => {
    if (marketingPagesContainer.isBound(MARKETING_PAGES_SYMBOLS.IPagesRepository)) {
      marketingPagesContainer.unbind(MARKETING_PAGES_SYMBOLS.IPagesRepository);
    }
    if (marketingPagesContainer.isBound(MARKETING_PAGES_SYMBOLS.ISiteSettingsRepository)) {
      marketingPagesContainer.unbind(MARKETING_PAGES_SYMBOLS.ISiteSettingsRepository);
    }
    marketingPagesContainer
      .bind<IPagesRepository>(MARKETING_PAGES_SYMBOLS.IPagesRepository)
      .toConstantValue(new MockPagesRepository());
    marketingPagesContainer
      .bind<ISiteSettingsRepository>(MARKETING_PAGES_SYMBOLS.ISiteSettingsRepository)
      .toConstantValue(new MockSiteSettingsRepository());
  });

  it("fetches a page by slug via tRPC and returns the domain entity", async () => {
    const caller = marketingPagesRouter.createCaller({});
    const page = await caller.pageBySlug({ slug: "about" });
    expect(page?.title).toBe("About");
    expect(page?.hero.heading).toBe("About us");
    expect(page?.status).toBe("published");
  });
});
