package cn.sagacloud.server.algorithm.services.json

import cn.sagacloud.server.algorithm.models.entities.BaseComponent
import cn.sagacloud.server.algorithm.models.jsonAnalyzer.AllComponents
import cn.sagacloud.server.algorithm.models.jsonAnalyzer.BaseObj
import cn.sagacloud.server.algorithm.services.CommonService
import com.sybotan.database.SFilter
import com.sybotan.service.SObjectService
import com.sybotan.service.models.enums.SResponseType
import com.sybotan.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)
    }
}