import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule } from '@nestjs/config';
import { User } from 'apps/auth/src/user/user.entity';
import { Marchantuser } from 'apps/auth/src/merchantuser/merchantuser.entity';
import { Merchant } from 'apps/merchant/src/merchant.entity';
import { MerchantLocation } from 'apps/merchant/src/location/location.entity';
import { MerchantDocumnets } from 'apps/merchant/src/merchantdocuments/merchantdocuments.entity';
import { MerchantType } from 'apps/merchant/src/merchanttype/merchanttype.entity';
import { MerchantCategory } from 'apps/merchant/src/merchantcategory/merchantcategory.entity';
import { MerchantHasCategories } from 'apps/merchant/src/merchant-has-category/merchant-has-category.entity';
import { Customer } from 'apps/customer/src/customer.entity';
import { CustomerLog } from 'apps/customer/src/customerlog/customerlog.entity';
import { MerchantLog } from 'apps/merchant/src/merchantlog/merchantlog.entity';
import { SMSTemplates } from 'apps/auth/src/sms-template/sms-template.entity';
import { SMSHistory } from 'apps/auth/src/sms-history/sms-history.entity';
import { Blacklists } from 'apps/auth/src/blacklist/blacklist.entity';
import { BlackListlog } from 'apps/auth/src/blacklistlog/blacklistlog.entity';
import { DefaultCreditLimit } from 'apps/auth/src/defaultcreaditlimit/defaultcreaditlimit.entity';
import { ShopItem } from 'apps/shop/src/shopitem.entity';
import { ShopItemCategory } from 'apps/shop/src/shopitemcategory/shopitemcategory.entity';
import { CustomerVerifications } from 'apps/customer/src/customerverifications/customerverification.entity';
import { ShopItemSubCategory } from 'apps/shop/src/shopitemsubcategory/shopitemsubcategory.entity';
import { PaymentMethods } from 'apps/customer/src/paymentmethods/paymentmethods.entity';
import { CustomerSavings } from 'apps/customer/src/customersavings/customersavings.entity';
import { CustomerSavingLog } from 'apps/customer/src/customersavinglog/customersavinglog.entity';

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    TypeOrmModule.forRoot({
      type: 'mysql',
      host: process.env.LOGIN_DB_HOST,
      port: parseInt(process.env.LOGIN_DB_PORT, 10),
      username: process.env.LOGIN_DB_USERNAME,
      password: process.env.LOGIN_DB_PASSWORD,
      database: process.env.LOGIN_DB_NAME,
      entities: [
        User,
        Marchantuser,
        Merchant,
        MerchantLocation,
        MerchantDocumnets,
        MerchantType,
        MerchantCategory,
        MerchantHasCategories,
        Customer,
        CustomerLog,
        MerchantLog,
        SMSTemplates,
        SMSHistory,
        Blacklists,
        BlackListlog,
        DefaultCreditLimit,
        ShopItem,
        ShopItemCategory,
        CustomerVerifications,
        ShopItemSubCategory,
        PaymentMethods,
        CustomerSavings,
        CustomerSavingLog,
        __dirname + '/../../**/*.entity{.ts,.js}',
      ],
      synchronize: true,
      logging: false,
    }),
  ],
})
export class TypeOrmSharedModule {}
