import {ObjectTreesApplicationInterface} from '../../application.interface';
import {ExtensionProvider} from '../../integration/extension.provider';
import {ROOT_CONFIG_PROVIDER} from '../../services/root-config/root-config.const';
import {RootConfigProvider} from '../../services/root-config/root-config.provider';
import {ContentEncryptedObjectProvider} from '../content-encrypted-object/content-encrypted-object.provider';
import {ServerConfigProvider} from '../server-config/server-config.provider';
import {
  LOGS_TYPE,
  LOG_PROVIDER,
  ROOT_CONFIGURATION_LOGS_SUBTYPE,
} from './log.const';
import {LogService} from './log.service';

export class LogProvider extends ExtensionProvider {
  constructor(protected app: ObjectTreesApplicationInterface) {
    super(LOG_PROVIDER, app);
    this.requiredProviders.push(
      ContentEncryptedObjectProvider,
      RootConfigProvider,
      ServerConfigProvider,
    );
    this.services.push({cls: LogService});
    this.objectTypes.push(LOGS_TYPE);
    this.objectSubTypes.push(ROOT_CONFIGURATION_LOGS_SUBTYPE);

    this.objectTrees.logs = {
      parentNode: () =>
        this.appCtx.getExtensionContext(ROOT_CONFIG_PROVIDER).nodes
          .rootConfiguration.value,
      treeNodeTypeId: LOGS_TYPE.name,
      treeNodeName: LOGS_TYPE.name,
      tree: {treeNode: {}, children: {}},
    };
  }

  async boot(): Promise<void> {
    await super.boot();
  }
}
