// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { AllowedFeatureFlagTypes } from "../../../enums/feature-flag.enum";
import { BaseResponse } from "../../../models/response/base.response";
import { Region } from "../../abstractions/environment.service";

export class ServerConfigResponse extends BaseResponse {
  version: string;
  gitHash: string;
  server: ThirdPartyServerConfigResponse;
  environment: EnvironmentServerConfigResponse;
  featureStates: { [key: string]: AllowedFeatureFlagTypes } = {};
  push: PushSettingsConfigResponse;
  settings: ServerSettingsResponse;
  communication: CommunicationServerConfigResponse;

  constructor(response: any) {
    super(response);

    if (response == null) {
      return;
    }

    this.version = this.getResponseProperty("Version");
    this.gitHash = this.getResponseProperty("GitHash");
    this.server = new ThirdPartyServerConfigResponse(this.getResponseProperty("Server"));
    this.environment = new EnvironmentServerConfigResponse(this.getResponseProperty("Environment"));
    this.featureStates = this.getResponseProperty("FeatureStates");
    this.push = new PushSettingsConfigResponse(this.getResponseProperty("Push"));
    this.settings = new ServerSettingsResponse(this.getResponseProperty("Settings"));
    this.communication = new CommunicationServerConfigResponse(
      this.getResponseProperty("Communication"),
    );
  }
}

export class ServerSettingsResponse extends BaseResponse {
  disableUserRegistration: boolean = false;
  suppressOnboardingInterstitials: boolean = false;

  constructor(response: any) {
    super(response);

    if (response == null) {
      return;
    }

    this.disableUserRegistration = this.getResponseProperty("DisableUserRegistration") ?? false;
    this.suppressOnboardingInterstitials =
      this.getResponseProperty("SuppressOnboardingInterstitials") ?? false;
  }
}

export class PushSettingsConfigResponse extends BaseResponse {
  pushTechnology: number;
  vapidPublicKey: string;

  constructor(data: any = null) {
    super(data);

    if (data == null) {
      return;
    }

    this.pushTechnology = this.getResponseProperty("PushTechnology");
    this.vapidPublicKey = this.getResponseProperty("VapidPublicKey");
  }
}

export class EnvironmentServerConfigResponse extends BaseResponse {
  cloudRegion: Region;
  vault: string;
  api: string;
  identity: string;
  notifications: string;
  sso: string;
  fillAssistRules: string;

  constructor(data: any = null) {
    super(data);

    if (data == null) {
      return;
    }

    this.cloudRegion = this.getResponseProperty("CloudRegion");
    this.vault = this.getResponseProperty("Vault");
    this.api = this.getResponseProperty("Api");
    this.identity = this.getResponseProperty("Identity");
    this.notifications = this.getResponseProperty("Notifications");
    this.sso = this.getResponseProperty("Sso");
    this.fillAssistRules = this.getResponseProperty("FillAssistRules");
  }
}

export class ThirdPartyServerConfigResponse extends BaseResponse {
  name: string;
  url: string;

  constructor(data: any = null) {
    super(data);

    if (data == null) {
      return;
    }

    this.name = this.getResponseProperty("Name");
    this.url = this.getResponseProperty("Url");
  }
}

export class CommunicationServerConfigResponse extends BaseResponse {
  bootstrap: BootstrapServerConfigResponse;

  constructor(data: any = null) {
    super(data);

    if (data == null) {
      return;
    }

    this.bootstrap = new BootstrapServerConfigResponse(this.getResponseProperty("Bootstrap"));
  }
}

export class BootstrapServerConfigResponse extends BaseResponse {
  type: string;
  idpLoginUrl: string;
  cookieName: string;
  cookieDomain: string;

  constructor(data: any = null) {
    super(data);

    if (data == null) {
      return;
    }

    this.type = this.getResponseProperty("Type");
    this.idpLoginUrl = this.getResponseProperty("IdpLoginUrl");
    this.cookieName = this.getResponseProperty("CookieName");
    this.cookieDomain = this.getResponseProperty("CookieDomain");
  }
}
