import { Module } from "@nestjs/common";
import { JwtModule } from "@nestjs/jwt";
import { MongooseModule } from "@nestjs/mongoose";
import { MulterModule } from "@nestjs/platform-express";
import { AuthController } from "./auth.controller";
import { AuthService } from "./auth.service";
import { DatabaseSeeder } from "./database.seeder";
import { ExtractionController } from "./extraction.controller";
import { InventoryController } from "./inventory.controller";
import { InventoryService } from "./inventory.service";
import { ItemsController } from "./items.controller";
import { ItemsService } from "./items.service";
import { JwtAuthGuard } from "./jwt-auth.guard";
import { NotificationsController } from "./notifications.controller";
import { NotificationsService } from "./notifications.service";
import { ReportsController } from "./reports.controller";
import { ReportsService } from "./reports.service";
import { Batch, BatchSchema } from "./schemas/batch.schema";
import { InventoryBalance, InventoryBalanceSchema } from "./schemas/inventory-balance.schema";
import { InventoryThresholdState, InventoryThresholdStateSchema } from "./schemas/inventory-threshold-state.schema";
import { InventoryTransaction, InventoryTransactionSchema } from "./schemas/inventory-transaction.schema";
import { Item, ItemSchema } from "./schemas/item.schema";
import { Notification, NotificationSchema } from "./schemas/notification.schema";
import { StockMovementSheet, StockMovementSheetSchema } from "./schemas/stock-movement-sheet.schema";
import { StockInvoice, StockInvoiceSchema } from "./schemas/stock-invoice.schema";
import { StockTransaction, StockTransactionSchema } from "./schemas/stock-transaction.schema";
import { User, UserSchema } from "./schemas/user.schema";
import { Warehouse, WarehouseSchema } from "./schemas/warehouse.schema";
import { StockMovementSheetsController } from "./stock-movement-sheets.controller";
import { StockMovementSheetsService } from "./stock-movement-sheets.service";
import { StockTransactionsController } from "./stock-transactions.controller";
import { StockTransactionsService } from "./stock-transactions.service";
import { WarehousesController } from "./warehouses.controller";
import { WarehousesService } from "./warehouses.service";

const mongooseFeatures = MongooseModule.forFeature([
  { name: Warehouse.name, schema: WarehouseSchema },
  { name: Item.name, schema: ItemSchema },
  { name: Batch.name, schema: BatchSchema },
  { name: InventoryTransaction.name, schema: InventoryTransactionSchema },
  { name: InventoryBalance.name, schema: InventoryBalanceSchema },
  { name: InventoryThresholdState.name, schema: InventoryThresholdStateSchema },
  { name: User.name, schema: UserSchema },
  { name: Notification.name, schema: NotificationSchema },
  { name: StockTransaction.name, schema: StockTransactionSchema },
  { name: StockMovementSheet.name, schema: StockMovementSheetSchema },
  { name: StockInvoice.name, schema: StockInvoiceSchema },
]);

@Module({
  imports: [
    MongooseModule.forRoot(process.env.MONGODB_URI ?? "mongodb://localhost:27017/silal-manual"),
    mongooseFeatures,
    MulterModule.register({ limits: { fileSize: 20 * 1024 * 1024 } }), // 20 MB max
    JwtModule.register({
      secret: process.env.JWT_SECRET ?? "ssmt-secret-key-change-in-production",
      signOptions: { expiresIn: "8h" },
    }),
  ],
  controllers: [
    AuthController,
    ExtractionController,
    InventoryController,
    WarehousesController,
    ItemsController,
    NotificationsController,
    ReportsController,
    StockTransactionsController,
    StockMovementSheetsController,
  ],
  providers: [
    AuthService,
    JwtAuthGuard,
    InventoryService,
    WarehousesService,
    ItemsService,
    NotificationsService,
    ReportsService,
    StockTransactionsService,
    StockMovementSheetsService,
    DatabaseSeeder,
  ],
})
export class AppModule {}
