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)
    aapw.appWindowUniqIdent = aapw.appWindowUniqIdent || aapw.appWindowIdent
    return (aapw)
  },
  csDataSet: class csDataSet {
    constructor(ds){
      this.appWindowIdent =null
      this.appWindowUniqIdent = null
      this.dataSetIdent = null
      this.keyFieldsIdents = []
      this.crLocData = 0
      this.errorFields = {}
      this.infoFields = {}
      this.warningFields = {}
      this.addRoutingData = 0
      this.hasSessionData = 0
      this.rowsInsertActionIdent = null
      this.rowsUpdateActionIdent = null
      this.rowsDeleteActionIdent = null
      this.pivotUpdateActionIdent = null
      this.pivotData = 0
      this.state = 2
      this.actions = []
      this.pageSize = constans.dataSet.pageSize
      this.pageNo = constans.dataSet.pageNo
      this.pageNoLock = 0
      this.where = {}
      this.whereOnCFActionIdents = []
      this.whereLists = {}
      this.order = {}
      this.currentRowIndex = -1
      this.currentRowFilter = null
      this.aggregates = [{ count: 0 }]
      this.rows = []
      this.selectedRows = []
      this.dataSetsFrom = []
      this.dataSetsTo = []
      this.isSet = 0
      this.isVis = 1
      this.refReq = 1
      this.refCount = 0
      this.refreshAggregates = 1
      this.ord = 1
      this.sortIdents = [{sortIdent: 'default', sortTranslatedDesc: 'Domyślnie'}]
      this.pageSizesIdents = [{ pageSizesIdent: '20', pageSizesTranslatedDesc: '20', pageSize: 20 }]
      this.pageSizesIdent = '20'
      this.layoutIdents = [
        constructors.csLayout()
      ]
      this.layoutIdent = 'default'
      this.fieldsIdents = []
      this.fieldsOnCFActionIdents = []
      this.pivotCurrentRowIndex = -1
      this.pivotCurrentColIndex = -1
      this.pivotPrevRowIndex = -1
      this.pivotPrevColIndex = -1
      this.pivotCurrentDataFieldIdent = null
      this.pivotPrevDataFieldIdent = null
      this.pivotRows = []
      this.pivotCols = []
      this.pivotValues = {}
      this.pivotRowsAggregates = [{ count: 0 }]
      this.pivotColsAggregates = [{ count: 0 }]
      this.scrollDirection = 0
      this.files = []
      Object.assign(this, ds)
      this.appWindowUniqIdent = this.appWindowUniqIdent || this.appWindowIdent
    }
  },
  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: class csRow{
    constructor(row){
      this.__uuid = uuid.v1()
      this._actionState = {}
      this._lookupVisible = {}
      this._status = 5
      this._errorFields = {}
      this._infoFields = {}
      this._warningFields = {}
      this._showAdditionalInfo = 0
      this._additionalInfoHeight = null
      this._isSelected = 0
      this._isCurrent = 0
      this._dataSetIdent = null
      this._appWindowIdent = null
      this._sourceKind = 'rows'
      Object.assign(this, row)
    }
  },
  csLayout(l){
    let lo = {
      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,
      global: 0,
      default: 0,
      owner: 0,
      device: 'all',
      usrDef: 0
    }
    Object.assign(lo, l)
    return (lo)
  },
  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
