import { Module } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs';
import { AddFavoriteHandler } from './application/commands/add-favorite/add-favorite.handler';
import { RemoveFavoriteHandler } from './application/commands/remove-favorite/remove-favorite.handler';
import { IsFavoritedHandler } from './application/queries/is-favorited/is-favorited.handler';
import { ListFavoritesHandler } from './application/queries/list-favorites/list-favorites.handler';
import { SAVED_LISTING_REPOSITORY } from './domain/repositories/saved-listing.repository';
import { PrismaSavedListingRepository } from './infrastructure/repositories/prisma-saved-listing.repository';
import { FavoritesController } from './presentation/controllers/favorites.controller';

const CommandHandlers = [AddFavoriteHandler, RemoveFavoriteHandler];
const QueryHandlers = [ListFavoritesHandler, IsFavoritedHandler];

@Module({
  imports: [CqrsModule],
  controllers: [FavoritesController],
  providers: [
    { provide: SAVED_LISTING_REPOSITORY, useClass: PrismaSavedListingRepository },
    ...CommandHandlers,
    ...QueryHandlers,
  ],
  exports: [SAVED_LISTING_REPOSITORY],
})
export class FavoritesModule {}
