import constans from './constans'
import { uuid } from 'vue-uuid'

const constructors = {
  csAppWindow(apw) {
    let aapw = {
      appWindowIdent: null,
      csAppNameSpacesG: null,
      appWindowUniqIdent: null,
      appWindowTranslatedDesc: null,
      viewHTML: null,
      state: 1,
      dataSets: {},
      dataSetsMaxOrd: 5,
      lookupDef: null,
      params: null,
      commands: null,
      queryDataSetsTo: [],
      query: {},
      modalWindows: {},
      stateChangeCount: 0
    }
    Object.assign(aapw, apw)
    return (aapw)
  },
  csDataSet(ds) {
    let dso = {
      dataSetIdent: null,
      keyFieldsIdents: [],
      crLocData: 0,
      errorFields: {},
      infoFields: {},
      warningFields: {},
      addRoutingData: 0,
      hasSessionData: 0,
      rowsInsertActionIdent: null,
      rowsUpdateActionIdent: null,
      rowsDeleteActionIdent: null,
      pivotUpdateActionIdent: null,
      pivotData: 0,
      state: 2,
      actions: [],
      pageSize: constans.dataSet.pageSize,
      pageNo: constans.dataSet.pageNo,
      pageNoLock: 0,
      where: {},
      whereOnCFActionIdents: [],
      whereLists: {},
      order: {},
      currentRowIndex: -1,
      currentRowFilter: null,
      aggregates: [{ count: 0 }],
      rows: [],
      selectedRows: [],
      dataSetsFrom: [],
      dataSetsTo: [],
      isSet: 0,
      isVis: 1,
      refReq: 1,
      refCount: 0,
      refreshAggregates: 1,
      ord: 1,
      sortIdents: [{sortIdent: 'default', sortTranslatedDesc: 'Domyślnie'}],
      pageSizesIdents: [{ pageSizesIdent: '20', pageSizesTranslatedDesc: '20', pageSize: 20 }],
      pageSizesIdent: '20',
      layoutIdents: [
        {
          layoutIdent: 'default', 
          layoutTranslatedDesc: 'Domyślnie', 
          filterFields: [],
          colFields: [], 
          rowFields: [],
          aggrFields: [],
          pageSizeX: constans.dataSet.pageSizeX,
          pageSizeY: constans.dataSet.pageSizeY,
          pageNoX: constans.dataSet.pageNoX,
          pageNoY: constans.dataSet.pageNoY,
          sortIdents: [{sortIdent: 'default', sortTranslatedDesc: 'Domyślnie', ord: 1, isUsrDefined: 0, sortColFields:[], currentSortColFieldIndex: 0}],
          sortIdent: 'default',
          currentColFieldIndex: 0
        }
      ],
      layoutIdent: 'default',
      fieldsIdents: [],
      fieldsOnCFActionIdents: [],
      pivotCurrentRowIndex: -1,
      pivotCurrentColIndex: -1,
      pivotPrevRowIndex: -1,
      pivotPrevColIndex: -1,
      pivotCurrentDataFieldIdent: null,
      pivotPrevDataFieldIdent: null,
      pivotRows: [],
      pivotCols: [],
      pivotValues: {},
      pivotRowsAggregates: [{ count: 0 }],
      pivotColsAggregates: [{ count: 0 }],
      scrollDirection: 0,
      files: []
    }
    Object.assign(dso, ds)
    return (dso)
  },
  csDataSetFromData(ds) {
    let dso = {
      rows: [],
      pivotRows: [],
      pivotCols: [],
      pivotValues: []
    }
    Object.assign(dso, ds)
    return (dso)
  },
  csAction(as) {
    let aso = {
      isAuto: 1,
      state: 1,
      addCurrentRow: 1,
      addWhere: 1,
      fieldsIdents: [],
      sources: [],
      showView: 0,
      viewHTML: null,
      addNewRow: 0,
      timer: null,
      clearSelectedRows: 0,
      addLayout: 0
    }
    Object.assign(aso, as)
    return (aso)
  },
  csRow(row){
    let rowo = {
      __uuid: uuid.v1(),
      _actionState: {},
      _lookupVisible: {},
      _status: 5,
      _errorFields: {},
      _infoFields: {},
      _warningFields: {},
      _showAdditionalInfo: 0,
      _additionalInfoHeight: null,
      _isSelected: 0,
      _isCurrent: 0,
      _dataSetIdent: null,
      _appWindowIdent: null,
      _sourceKind: 'rows'
    }
    Object.assign(rowo, row)
    return (rowo)
  },
  csDataSetLinkFrom(dsl) {
    let dslo = {
      appWindowIdentFrom: null,
      dataSetIdentFrom: null,
      sourceKindFrom: 0,
      dataFieldIdentFrom: null,
      dataFieldIdentTo: null,
      sourceKindTo: 0
    }
    Object.assign(dslo, dsl)
    return (dslo)
  },
  csDataSetLinkTo(dsl) {
    let dslo = {
      appWindowIdentTo: null,
      dataSetIdentTo: null,
      dataFieldIdentTo: null,
      sourceKindTo: 0,
      dataFieldIdentFrom: null
    }
    Object.assign(dslo, dsl)
    return (dslo)
  },
  csLookupDefs(dsl) {
    let dslo = {
      appWindowIdent: null,
      dataSetIdent: null,
      dataFieldIdent: null,
      appWindowIdentLookup: null,
      sourceKind: null,
      isMultiSelect: 0,
      lookupGetters: [],
      lookupSetters: [],
      lookupVisible: false,
      appWindowUniqIdent: null
    }
    Object.assign(dslo, dsl)
    return (dslo)
  },
  csWhereFieldsIdent(wfi) {
    let wf = {
      dataFieldIdent: null,
      dataFieldColTranslatedDesc: null,
      dataFieldLabTranslatedDesc: null,
      dataFieldWatermarkTranslatedDesc: null,
      formatType: null,
      dataFieldValueDef: null,
      linkedParamName: null,
      onCFActionIdent: null
    }
    Object.assign(wf, wfi)
    return (wf)
  }
}
export default constructors
