package com.persagy.revit.services.json

import com.persagy.database.SFilter
import com.persagy.revit.models.entities.BaseComponent
import com.persagy.revit.models.jsonAnalyzer.AllComponents
import com.persagy.revit.models.jsonAnalyzer.BaseObj
import com.persagy.revit.services.CommonService
import com.persagy.service.SObjectService
import com.persagy.service.models.enums.SResponseType
import com.persagy.service.models.requests.SCreateRequest

/**
 *
 *
 * @author jxing
 */
object BaseBehavier {
    fun analyze(service: SObjectService<BaseComponent>, baseObj: BaseObj<AllComponents>, objects : ArrayList<BaseComponent>?): Boolean {
        if(objects == null || objects.isEmpty())
            return true
        for(obj in objects){
            obj.id = CommonService.generateUUID(null, true)
            obj.modelId = baseObj.modelId
        }
        service.delete(SFilter.eq("modelId", baseObj.modelId!!))
        val create = SCreateRequest<BaseComponent>()
        create.content = objects
        val result = service.createList(create)
        return SResponseType.success.equals(result.result)
    }
}