import { ContainerModule, type interfaces } from "inversify";

import type { IPagesRepository } from "../application/repositories/pages.repository.interface";
import type { ISiteSettingsRepository } from "../application/repositories/site-settings.repository.interface";
import { MockPagesRepository } from "../infrastructure/repositories/pages.repository.mock";
import { MockSiteSettingsRepository } from "../infrastructure/repositories/site-settings.repository.mock";
import {
  getPageBySlugUseCase,
  type IGetPageBySlugUseCase,
} from "../application/use-cases/get-page-by-slug.use-case";
import {
  getSiteSettingsUseCase,
  type IGetSiteSettingsUseCase,
} from "../application/use-cases/get-site-settings.use-case";
import {
  getPageBySlugController,
  type IGetPageBySlugController,
} from "../interface-adapters/controllers/get-page-by-slug.controller";
import {
  getSiteSettingsController,
  type IGetSiteSettingsController,
} from "../interface-adapters/controllers/get-site-settings.controller";
import { MARKETING_PAGES_SYMBOLS } from "./symbols";

export const MarketingPagesModule = new ContainerModule(
  (bind: interfaces.Bind) => {
    bind<IPagesRepository>(MARKETING_PAGES_SYMBOLS.IPagesRepository).to(
      MockPagesRepository,
    );
    bind<ISiteSettingsRepository>(
      MARKETING_PAGES_SYMBOLS.ISiteSettingsRepository,
    ).to(MockSiteSettingsRepository);

    bind<IGetPageBySlugUseCase>(MARKETING_PAGES_SYMBOLS.IGetPageBySlugUseCase).toDynamicValue(
      (ctx) =>
        getPageBySlugUseCase(
          ctx.container.get<IPagesRepository>(MARKETING_PAGES_SYMBOLS.IPagesRepository),
        ),
    );

    bind<IGetSiteSettingsUseCase>(MARKETING_PAGES_SYMBOLS.IGetSiteSettingsUseCase).toDynamicValue(
      (ctx) =>
        getSiteSettingsUseCase(
          ctx.container.get<ISiteSettingsRepository>(
            MARKETING_PAGES_SYMBOLS.ISiteSettingsRepository,
          ),
        ),
    );

    bind<IGetPageBySlugController>(
      MARKETING_PAGES_SYMBOLS.IGetPageBySlugController,
    ).toDynamicValue((ctx) =>
      getPageBySlugController(
        ctx.container.get<IGetPageBySlugUseCase>(MARKETING_PAGES_SYMBOLS.IGetPageBySlugUseCase),
      ),
    );

    bind<IGetSiteSettingsController>(
      MARKETING_PAGES_SYMBOLS.IGetSiteSettingsController,
    ).toDynamicValue((ctx) =>
      getSiteSettingsController(
        ctx.container.get<IGetSiteSettingsUseCase>(
          MARKETING_PAGES_SYMBOLS.IGetSiteSettingsUseCase,
        ),
      ),
    );
  },
);
