package com.persagy.revit.services.modelCheck


import com.alibaba.fastjson.JSON
import com.alibaba.fastjson.TypeReference
import com.persagy.revit.backstage.model.CreateRequest
import com.persagy.revit.backstage.model.CreateResponse
import com.persagy.revit.backstage.model.QueryRequest
import com.persagy.revit.backstage.model.QueryResponse
import com.persagy.revit.models.config.MyProperties
import com.persagy.revit.models.modelFile.DownloadEntity
import com.persagy.revit.models.modelFile.TaskEntity
import com.persagy.revit.models.modelFile.TaskResultEntity
import com.persagy.revit.services.http.HttpService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component

/**
 *
 *
 * @author jxing
 */
@Component
class TaskRequest {
    @Autowired
    lateinit var properties: MyProperties

    fun createTask(request : CreateRequest<TaskEntity>) : CreateResponse<TaskEntity>?{
        var postBody = JSON.toJSONString(request)
        val resultStr = HttpService.sendPost(properties.scheduler.createTask, postBody)
        return JSON.parseObject(resultStr, object : TypeReference<CreateResponse<TaskEntity>>() { })
    }

    fun createDownload(request : CreateRequest<DownloadEntity>) : CreateResponse<DownloadEntity> {
        var postBody = JSON.toJSONString(request)
        val resultStr = HttpService.sendPost(properties.scheduler.createDownload, postBody)
        return JSON.parseObject(resultStr, object : TypeReference<CreateResponse<DownloadEntity>>() { })
    }

    fun queryTask(request : QueryRequest) : QueryResponse<TaskEntity> {
        var postBody = JSON.toJSONString(request)
        val resultStr = HttpService.sendPost(properties.scheduler.queryTask, postBody)
        return JSON.parseObject(resultStr, object : TypeReference<QueryResponse<TaskEntity>>() { })
    }

    fun queryTaskResult(request : QueryRequest) : QueryResponse<TaskResultEntity> {
        var postBody = JSON.toJSONString(request)
        val resultStr = HttpService.sendPost(properties.scheduler.queryTaskResult, postBody)
        return JSON.parseObject(resultStr, object : TypeReference<QueryResponse<TaskResultEntity>>() { })
    }
}