import { Form } from '../../e2elib/lib/src/pageobjects/form.component'; 
 | 
import { ListRow } from '../../e2elib/lib/src/pageobjects/list/listrow.component'; 
 | 
import { DialogAccount } from '../dialogs/dialog.account'; 
 | 
import { ListSOP } from '../../libappsop/listsop'; 
 | 
  
 | 
export class FormAccount extends Form { 
 | 
  public listAccount = new ListAccount(); 
 | 
  
 | 
  public constructor() { 
 | 
    super('FormAccountStructure'); 
 | 
  } 
 | 
} 
 | 
  
 | 
export class ListAccount extends ListSOP<DialogAccount, ListAccountColumn> { 
 | 
  public static readonly title = 'Accounts'; 
 | 
  public constructor() { 
 | 
    super('ListAccountStructure', new DialogAccount()); 
 | 
  
 | 
    // Set primary key column name(s), to display in error message when assert fails 
 | 
    this.rowPrimaryColumnNames = { Name: '' }; 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Check if the account name exist in the rows 
 | 
   * 
 | 
   * @param accName Name column value 
 | 
   * @param rows Array of ListRow to find from 
 | 
   */ 
 | 
  public async isAccountExistInRows(accName: string, rows: ListRow[]): Promise<boolean> { 
 | 
    for (const row of rows) { 
 | 
      const rowName = await this.getCellValueFromRow(ListAccountStructureColumn.Name, row); 
 | 
      if (rowName === accName) { 
 | 
        return true; 
 | 
      } 
 | 
    } 
 | 
    return false; 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Find account by cost driver 
 | 
   * 
 | 
   * @param costDriver Cost driver column value 
 | 
   * @returns Return an array of ListRow 
 | 
   */ 
 | 
  public async findAccountByCostDriver(costDriver: string): Promise<ListRow[]> { 
 | 
    const results: ListRow[] = []; 
 | 
    const rows = await this.getAllRows(); 
 | 
    for (const row of rows) { 
 | 
      if ((await (await row.getCell(ListAccountStructureColumn.DefaultCostDriver)).getValue()) === costDriver) { 
 | 
        results.push(row); 
 | 
      } 
 | 
    } 
 | 
    return results; 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Create account by passing neccessary field values 
 | 
   * 
 | 
   * @param parentAccount Parent account field value 
 | 
   * @param name Name field value 
 | 
   * @param reportType Report type field value 
 | 
   * @param budget Budget field value 
 | 
   * @param costDriver Cost driver field value 
 | 
   * @param cost Cost field value 
 | 
   * @param timeUnit Time unit field value 
 | 
   * @param lengthOfTime Length of time field value 
 | 
   * @returns Boolean to indicate if it is successful 
 | 
   */ 
 | 
  public async createAccount( 
 | 
    parentAccount?: string, 
 | 
    name?: string, 
 | 
    reportType?: string, 
 | 
    budget?: string, 
 | 
    costDriver?: string, 
 | 
    cost?: string, 
 | 
    timeUnit?: string, 
 | 
    lengthOfTime?: string, 
 | 
  ): Promise<boolean> { 
 | 
    const [dlg] = await this.selectContextMenu(listAccountContextMenuItem.Create); 
 | 
  
 | 
    await dlg.updateDialogValues({ 
 | 
      ParentAccountName: parentAccount, 
 | 
      Name: name, 
 | 
      ReportType: reportType, 
 | 
      Budget: budget, 
 | 
      CostDriver: costDriver, 
 | 
      Cost: cost, 
 | 
      TimeUnit: timeUnit, 
 | 
      LengthOfTime: lengthOfTime, 
 | 
    }); 
 | 
    return dlg.clickOK(); 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Check if the cost driver of the account matches with any of the cost drivers 
 | 
   * 
 | 
   * @param accName Name column value 
 | 
   * @param costDrivers Cost driver column value 
 | 
   */ 
 | 
  public async isAccountCostDriverMatch(accName: string, costDrivers: string[]): Promise<boolean> { 
 | 
    const row = await this.getRowByValue([{ columnID: ListAccountStructureColumn.Name, value: accName }]); 
 | 
    const rowCostDriver = await (await row.getCell(ListAccountStructureColumn.DefaultCostDriver)).getValue(); 
 | 
    return costDrivers.indexOf(rowCostDriver) > -1; 
 | 
  } 
 | 
  
 | 
  /** 
 | 
   * Open account dialog via "Edit" context menu 
 | 
   * 
 | 
   * @returns account dialog 
 | 
   */ 
 | 
  public async openAcountDialogViaEditContextMenu(listRow: ListRow): Promise<DialogAccount> { 
 | 
    const [dlg] = await this.selectContextMenu(listAccountContextMenuItem.Edit, listRow); 
 | 
    return dlg; 
 | 
  } 
 | 
} 
 | 
  
 | 
export enum ListAccountStructureColumn { 
 | 
  AccountType = 'Account type', 
 | 
  ReportType = 'Report type', 
 | 
  Name = 'Name', 
 | 
  DefaultCostDriver = 'Default cost driver', 
 | 
  DefaultCost = 'Default cost', 
 | 
  TimeUnit = 'Time unit', 
 | 
  Budget = 'Budget', 
 | 
} 
 | 
  
 | 
const listAccountContextMenuItem = { 
 | 
  Create: { ContextMenu: 'listContextMenuAccount', Name: 'MenuCreate', Label: 'Create' }, 
 | 
  Edit: { ContextMenu: 'listContextMenuAccount', Name: 'MenuEdit', Label: 'Edit' }, 
 | 
}; 
 | 
  
 | 
export { listAccountContextMenuItem as ListAccountContextMenuItem }; 
 | 
  
 | 
// Transition to new S&OP page objects, so suffix with "2". Once done refactoring, will remove "2" as above column enum will be removed 
 | 
export interface ListAccountColumn { 
 | 
  Name?: string; 
 | 
  'Account type'?: string; 
 | 
  'Report type'?: string; 
 | 
  'Default cost driver'?: string; 
 | 
  'Default cost'?: string; 
 | 
  'Time unit'?: string; 
 | 
  Budget?: string; 
 | 
} 
 | 
  
 | 
export enum ListAccountTypeImage { 
 | 
  Preferences = 'PREFERENCES', 
 | 
} 
 |