// ============================================================
// Lexware Office Integration - NestJS Module
// ============================================================

import { Module } from '@nestjs/common';
import { HttpModule } from '@nestjs/axios';
import { ConfigService } from '@nestjs/config';
import { CrmPrismaModule } from '../prisma/crm-prisma.module';
import { RedisModule } from '../redis/redis.module';
import { LexwareClientService } from './lexware-client.service';
import { LexwareContactsService } from './lexware-contacts.service';
import { LexwareVouchersService } from './lexware-vouchers.service';
import { LexwareSyncService } from './lexware-sync.service';
import { LexwareContactsController } from './lexware-contacts.controller';
import { LexwareVouchersController } from './lexware-vouchers.controller';

@Module({
  imports: [
    HttpModule.registerAsync({
      useFactory: (config: ConfigService) => ({
        baseURL: config.get<string>(
          'LEXWARE_API_URL',
          'https://api.lexware.io',
        ),
        timeout: 15000,
        headers: {
          Authorization: `Bearer ${config.get<string>('LEXWARE_API_KEY', '')}`,
          Accept: 'application/json',
          'Content-Type': 'application/json',
        },
      }),
      inject: [ConfigService],
    }),
    CrmPrismaModule,
    RedisModule,
  ],
  controllers: [LexwareContactsController, LexwareVouchersController],
  providers: [
    LexwareClientService,
    LexwareContactsService,
    LexwareVouchersService,
    LexwareSyncService,
  ],
  exports: [LexwareContactsService, LexwareVouchersService, LexwareClientService],
})
export class LexwareModule {}
