import { Injectable } from '@nestjs/common';
import { UpdateUserPrivilegeConfigurationManager } from './managers/update-user-privilege-configuration.manager';
import { UserPrivilegeConfigurationEntity } from '../../entities/user-privilege-configuration.entity';
import { UserPrivilegeConfigurationService } from '../../../data/service/user-privilege-configuration.service';
import { IndexUserPrivilegeConfigurationManager } from './managers/index-user-privilege-configuration.manager';
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { MenuUserPrivilegeConfigurationManager } from './managers/menu-user-privilege-configuration.manager';

@Injectable()
export class UserPrivilegeConfigurationDataOrchestrator {
  constructor(
    private updateManager: UpdateUserPrivilegeConfigurationManager,
    private indexManager: IndexUserPrivilegeConfigurationManager,
    private privilegeMenuManager: MenuUserPrivilegeConfigurationManager,
    private serviceData: UserPrivilegeConfigurationService,
  ) {}

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

  async index(
    params,
  ): Promise<PaginationResponse<UserPrivilegeConfigurationEntity>> {
    this.indexManager.setFilterParam(params);
    this.indexManager.setService(
      this.serviceData,
      TABLE_NAME.USER_PRIVILEGE_CONFIGURATION,
    );
    await this.indexManager.execute();
    return this.indexManager.getResult();
  }

  async privilegeMenu(
    params,
  ): Promise<PaginationResponse<UserPrivilegeConfigurationEntity>> {
    this.privilegeMenuManager.setFilterParam({
      page: 1,
      limit: 100,
      ...(params ?? {}),
    });

    this.privilegeMenuManager.setService(
      this.serviceData,
      TABLE_NAME.USER_PRIVILEGE_CONFIGURATION,
    );
    await this.privilegeMenuManager.execute();
    return this.privilegeMenuManager.getResult();
  }
}
