import { join, posix } from 'path';
import { LOCAL_AAI_CFG_DIR, REMOTE_AAI_CFG_DIR_LINUX } from '../paths';
import { getSystemId } from './system-id';

/*===================================================================
                      Device File Paths
===================================================================*/

export const DEVICE_CREDENTIALS_DIRECTORY_NAME = 'device';
export const DEVICE_CONFIG_FILE_NAME = 'alwaysai.device.json';

export function getDeviceConfigPath() {
  const systemId = getSystemId();
  return `${DEVICE_CREDENTIALS_DIRECTORY_NAME}${
    systemId !== 'production' ? '-' + systemId : ''
  }`;
}

/*===================================================================
              local alwaysai.device.json file setup
===================================================================*/

export function getLocalDeviceConfigDirectoryPath() {
  return join(LOCAL_AAI_CFG_DIR, getDeviceConfigPath());
}

export function getLocalDeviceConfigFilePath() {
  return join(getLocalDeviceConfigDirectoryPath(), DEVICE_CONFIG_FILE_NAME);
}

/*===================================================================
              remote alwaysai.device.json file setup
===================================================================*/

export function getRemoteDeviceConfigDirectoryPath() {
  return posix.join(REMOTE_AAI_CFG_DIR_LINUX, getDeviceConfigPath());
}

export function getRemoteDeviceConfigFilePath() {
  return posix.join(
    getRemoteDeviceConfigDirectoryPath(),
    DEVICE_CONFIG_FILE_NAME
  );
}
