import { inject, Injectable } from "@angular/core";

import { Api } from "../api/api";
import { UserModel } from "../../app/components/models/user.model";
import { AuthenticationService } from "../user/authentication.service";

@Injectable()
export abstract class AbstractBase
{
  protected readonly apiSvc = inject(Api);
  private readonly authSvc = inject(AuthenticationService);

  public get authService(): AuthenticationService
  {
    return this.authSvc;
  }

  public get currentUserValue(): UserModel
  {
    return this.authSvc.currentUserValue;
  }

  public getLabelSetting(settingId: number)
  {
    const params: any = { settingId: settingId };
    return this.apiSvc.post('v1/paramTypes/getLabelSetting', params);
  }

  public getLookupData(lookupType: number, excludeItemId: number = -1)
  {
    const params: any = { lookupType: lookupType, excludeItemId: excludeItemId };
    return this.apiSvc.post('v1/paramTypes/getLookupData', params);
  }

  public getLookupDataExt(lookupType: number)
  {
    const params: any = { lookupType: lookupType};
    return this.apiSvc.post('v1/paramTypes/getLookupDataExt', params);
  }

  static parseErrors(errors: any)
  {
    let retVal = '';
    if (errors)
    {
      for (const propery in errors)
      {
        retVal += propery + ': ' + errors[propery] + '\r\n';
      }
    }

    return retVal;
  }
}
