import { Module } from '@nestjs/common';
import { ClientProxyFactory, Transport } from '@nestjs/microservices';
import { MerchantGatewayController } from './controllers/merchantgateway/merchantgateway.controller';
import { TypeOrmSharedModule } from '@app/typeorm';
import { MerchantlocationController } from './controllers/merchantgateway/merchantlocation.controller';
import { MerchanttypeController } from './controllers/merchantgateway/merchanttype.controller';
import { MerchantcategorygatewayController } from './controllers/merchantgateway/merchantcategorygateway.controller';
import { StaticFileModule } from '@app/static-file';
import { CustomerGateWayController } from './controllers/customergateway/customergateway.controller';
import { customerLogGatewayController } from './controllers/customergateway/customerlogfateway.controller';
import { MerchantLogGatewayController } from './controllers/merchantgateway/merchantloggateway.controller';
import { AuthUserGateway } from './controllers/authgateway/authusergateway.controller';
import { AuthenticationGateway } from './controllers/authgateway/authgateway.controller';
import { AuthCoreLibModule } from 'libs/auth-core-lib/src/auth-core-lib.module';
import { SMSGateway } from './controllers/authgateway/smsgateway.controller';
import { SMSHistoryGateway } from './controllers/authgateway/smshistorygateway.controller';
import { BlackListGatewayController } from './controllers/authgateway/blacklistgateway.controller';
import { BlackListLogGatewayController } from './controllers/authgateway/blacklistloggateway.controller';
import { DefaultCreditLimitGateway } from './controllers/authgateway/defaultcreditlimitgateway.controller';
import { ShopItemGateway } from './controllers/shopgateway/shopitemgateway.controller';
import { ShopItemCategoryGateway } from './controllers/shopgateway/shopitemcategorygateway.controller';
import { CustomerVerificationGatewayController } from './controllers/customergateway/customerverificationgateway.controller';
import { ShopItemSubCategoryGateway } from './controllers/shopgateway/shopitemsubcategorygateway.controller';
import { PaymentMethodGatewayController } from './controllers/customergateway/paymentmethodgateway.controller';
import { CustomerSavingsGatewayController } from './controllers/customergateway/customersavinggateway.controller';
import { CustomerSavingLogGatewayController } from './controllers/customergateway/customersavingloggateway.controller';

@Module({
  imports: [TypeOrmSharedModule, StaticFileModule, AuthCoreLibModule],
  controllers: [
    MerchantGatewayController,
    MerchantlocationController,
    MerchanttypeController,
    MerchantcategorygatewayController,
    CustomerGateWayController,
    customerLogGatewayController,
    MerchantLogGatewayController,
    AuthUserGateway,
    AuthenticationGateway,
    SMSGateway,
    SMSHistoryGateway,
    BlackListGatewayController,
    BlackListLogGatewayController,
    DefaultCreditLimitGateway,
    ShopItemGateway,
    ShopItemCategoryGateway,
    CustomerVerificationGatewayController,
    ShopItemSubCategoryGateway,
    PaymentMethodGatewayController,
    CustomerSavingsGatewayController,
    CustomerSavingLogGatewayController,
  ],
  providers: [
    {
      provide: 'MERCHANT_SERVICE',
      useFactory: () => {
        return ClientProxyFactory.create({
          transport: Transport.TCP,
          options: {
            host: 'localhost',
            port: 8878,
          },
        });
      },
    },
    {
      provide: 'MERCHANT_LOCATION',
      useFactory: () => {
        return ClientProxyFactory.create({
          transport: Transport.TCP,
          options: {
            host: 'localhost',
            port: 8878,
          },
        });
      },
    },
    {
      provide: 'MERCHANT_TYPE',
      useFactory: () => {
        return ClientProxyFactory.create({
          transport: Transport.TCP,
          options: {
            host: 'localhost',
            port: 8878,
          },
        });
      },
    },
    {
      provide: 'MERCHANT_CATEGORY',
      useFactory: () => {
        return ClientProxyFactory.create({
          transport: Transport.TCP,
          options: {
            host: 'localhost',
            port: 8878,
          },
        });
      },
    },
    {
      provide: 'MERCHANT_LOG',
      useFactory: () => {
        return ClientProxyFactory.create({
          transport: Transport.TCP,
          options: {
            host: 'localhost',
            port: 8878,
          },
        });
      },
    },
    {
      //customer services will start from here
      provide: 'CUSTOMER_SERVICE',
      useFactory: () => {
        return ClientProxyFactory.create({
          transport: Transport.TCP,
          options: {
            host: 'localhost',
            port: 8879,
          },
        });
      },
    },
    {
      provide: 'CUSTOMER_LOG_SERVICE',
      useFactory: () => {
        return ClientProxyFactory.create({
          transport: Transport.TCP,
          options: {
            host: 'localhost',
            port: 8879,
          },
        });
      },
    }, //user sevices will start from here
    {
      provide: 'USER_SERVICE',
      useFactory: () => {
        return ClientProxyFactory.create({
          transport: Transport.TCP,
          options: {
            host: 'localhost',
            port: 8880,
          },
        });
      },
    },
    {
      //authservice
      provide: 'AUTH_SERVICE',
      useFactory: () => {
        return ClientProxyFactory.create({
          transport: Transport.TCP,
          options: {
            host: 'localhost',
            port: 8880,
          },
        });
      },
    },

    {
      //SMS_TEMPLATE
      provide: 'SMS_TEMPLATE',
      useFactory: () => {
        return ClientProxyFactory.create({
          transport: Transport.TCP,
          options: {
            host: 'localhost',
            port: 8880,
          },
        });
      },
    },
    {
      //shop
      provide: 'SHOP_SERVICE',
      useFactory: () => {
        return ClientProxyFactory.create({
          transport: Transport.TCP,
          options: {
            host: 'localhost',
            port: 8881,
          },
        });
      },
    },
  ],
})
export class AppModule {}
