export class GeneralConfig {

  // -----------------------------------
  // เพิ่ม attributes ของ config ทั่วไปตรงนี้
  // -----------------------------------
  useProxy: boolean = this.findConfigValue('USE_PROXY') === '1';
  splitRow: string = this.findConfigValue('SPLIT_ROW');
  splitColumn: string = this.findConfigValue('SPLIT_COL');

  constructor(private generalAttributes: GeneralAttributes[]) { }

  private findConfigValue(configName: string): string | null {
    const generalAttributes = this.generalAttributes.find((attrItem: GeneralAttributes) => attrItem.CONFIG_NAME === configName);
    if (generalAttributes !== undefined) {
      return generalAttributes.CONFIG_VALUE;
    } else {
      return null;
    }
  }

}


/**
 * ฟิลด์ที่อยู่ในตาราง APP_CONFIG
 */
export interface GeneralAttributes {
  /** CONFIG_NAME	NVARCHAR2(50 CHAR) */
  CONFIG_NAME: string;

  /** CONFIG_VALUE	NVARCHAR2(50 CHAR) */
  CONFIG_VALUE: string;

  /** CONFIG_DESCR	NVARCHAR2(255 CHAR) */
  CONFIG_DESCR: string;
}
