import { Injectable } from '@nestjs/common';
import { CreateTenantManager } from './managers/create-tenant.manager';
import { DeleteTenantManager } from './managers/delete-tenant.manager';
import { UpdateTenantManager } from './managers/update-tenant.manager';
import { BaseDataTransactionOrchestrator } from 'src/core/modules/domain/usecase/orchestrators/base-data-transaction.orchestrator';
import { ActiveTenantManager } from './managers/active-tenant.manager';
import { InactiveTenantManager } from './managers/inactive-tenant.manager';
import { ConfirmTenantManager } from './managers/confirm-tenant.manager';
import { STATUS } from 'src/core/strings/constants/base.constants';
import { BatchResult } from 'src/core/response/domain/ok-response.interface';
import { BatchConfirmTenantManager } from './managers/batch-confirm-tenant.manager';
import { BatchInactiveTenantManager } from './managers/batch-inactive-tenant.manager';
import { BatchActiveTenantManager } from './managers/batch-active-tenant.manager';
import { BatchDeleteTenantManager } from './managers/batch-delete-tenant.manager';
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity';
import { UpdatePasswordTenantManager } from './managers/update-password-tenant.manager';
import { UserDataService } from 'src/modules/user-related/user/data/services/user-data.service';

@Injectable()
export class TenantDataOrchestrator extends BaseDataTransactionOrchestrator<UserEntity> {
  constructor(
    private createManager: CreateTenantManager,
    private updateManager: UpdateTenantManager,
    private deleteManager: DeleteTenantManager,
    private activeManager: ActiveTenantManager,
    private confirmManager: ConfirmTenantManager,
    private inactiveManager: InactiveTenantManager,
    private batchDeleteManager: BatchDeleteTenantManager,
    private batchActiveManager: BatchActiveTenantManager,
    private batchConfirmManager: BatchConfirmTenantManager,
    private batchInactiveManager: BatchInactiveTenantManager,
    private updatePasswordManager: UpdatePasswordTenantManager,
    private serviceData: UserDataService,
  ) {
    super();
  }

  async create(data): Promise<UserEntity> {
    this.createManager.setData(data);
    this.createManager.setService(this.serviceData, TABLE_NAME.TENANT);
    await this.createManager.execute();
    await this.createManager.generateConfig();
    return this.createManager.getResult();
  }

  async update(dataId, data): Promise<UserEntity> {
    this.updateManager.setData(dataId, data);
    this.updateManager.setService(this.serviceData, TABLE_NAME.TENANT);
    await this.updateManager.execute();
    return this.updateManager.getResult();
  }

  async updatePassword(dataId, data): Promise<UserEntity> {
    this.updatePasswordManager.setData(dataId, data);
    this.updatePasswordManager.setService(this.serviceData, TABLE_NAME.TENANT);
    await this.updatePasswordManager.execute();
    return this.updatePasswordManager.getResult();
  }

  async delete(dataId): Promise<string> {
    this.deleteManager.setData(dataId);
    this.deleteManager.setService(this.serviceData, TABLE_NAME.TENANT);
    await this.deleteManager.execute();
    return this.deleteManager.getResult();
  }

  async batchDelete(dataIds: string[]): Promise<BatchResult> {
    this.batchDeleteManager.setData(dataIds);
    this.batchDeleteManager.setService(this.serviceData, TABLE_NAME.TENANT);
    await this.batchDeleteManager.execute();
    return this.batchDeleteManager.getResult();
  }

  async active(dataId): Promise<string> {
    this.activeManager.setData(dataId, STATUS.ACTIVE);
    this.activeManager.setService(this.serviceData, TABLE_NAME.TENANT);
    await this.activeManager.execute();
    return this.activeManager.getResult();
  }

  async batchActive(dataIds: string[]): Promise<BatchResult> {
    this.batchActiveManager.setData(dataIds, STATUS.ACTIVE);
    this.batchActiveManager.setService(this.serviceData, TABLE_NAME.TENANT);
    await this.batchActiveManager.execute();
    return this.batchActiveManager.getResult();
  }

  async confirm(dataId): Promise<string> {
    this.confirmManager.setData(dataId, STATUS.ACTIVE);
    this.confirmManager.setService(this.serviceData, TABLE_NAME.TENANT);
    await this.confirmManager.execute();
    return this.confirmManager.getResult();
  }

  async batchConfirm(dataIds: string[]): Promise<BatchResult> {
    this.batchConfirmManager.setData(dataIds, STATUS.ACTIVE);
    this.batchConfirmManager.setService(this.serviceData, TABLE_NAME.TENANT);
    await this.batchConfirmManager.execute();
    return this.batchConfirmManager.getResult();
  }

  async inactive(dataId): Promise<string> {
    this.inactiveManager.setData(dataId, STATUS.INACTIVE);
    this.inactiveManager.setService(this.serviceData, TABLE_NAME.TENANT);
    await this.inactiveManager.execute();
    return this.inactiveManager.getResult();
  }

  async batchInactive(dataIds: string[]): Promise<BatchResult> {
    this.batchInactiveManager.setData(dataIds, STATUS.INACTIVE);
    this.batchInactiveManager.setService(this.serviceData, TABLE_NAME.TENANT);
    await this.batchInactiveManager.execute();
    return this.batchInactiveManager.getResult();
  }
}
