package com.heyu.api.controller.imageseg;


import com.aliyun.imageseg20191230.models.ChangeSkyResponse;
import com.aliyun.imageseg20191230.models.ChangeSkyResponseBody;
import com.heyu.api.alibaba.handle.imageseg.AChangeSkyHandle;
import com.heyu.api.alibaba.request.imageseg.AChangeSkyRequest;
import com.heyu.api.controller.BaseController;
import com.heyu.api.data.annotation.CacheResult;
import com.heyu.api.data.annotation.NotIntercept;
import com.heyu.api.data.utils.ApiR;
import com.heyu.api.data.utils.R;
import com.heyu.api.request.imageseg.ChangeSkyReq;
import com.heyu.api.resp.imageseg.ChangeSkyResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/***
 *https://next.api.aliyun.com/api/imageseg/2019-12-30/ChangeSky
 *
 *天空替换 ChangeSky
 *
 * 功能描述
 * 输入两种图像，天空替换能力可以将参考图 B 的天空样式替换到目标图 A 中，从而改变目标图 A 的天空样式，实现换天功能。 关于该接口功能的示例图如下
 *
 *
 *
 */
@Slf4j
@RestController
@RequestMapping("/image")
@NotIntercept
public class ChangeSkyController extends BaseController {


    @Autowired
    private AChangeSkyHandle aChangeSkyHandle;


    @RequestMapping("/changeSky")
    @CacheResult
    public R changeSky(ChangeSkyReq request) {
        ChangeSkyResp resp = new ChangeSkyResp();

        AChangeSkyRequest aChangeSkyRequest = new AChangeSkyRequest();
        aChangeSkyRequest.setImageUrl(request.getImageUrl());
        aChangeSkyRequest.setImageBase64(request.getImageBase64());
        aChangeSkyRequest.setReplaceImageBase64(request.getReplaceImageBase64());
        aChangeSkyRequest.setReplaceImageURL(request.getReplaceImageURL());
        ApiR<ChangeSkyResponse> aR = aChangeSkyHandle.handle(aChangeSkyRequest);


        if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
            ChangeSkyResponseBody.ChangeSkyResponseBodyData responseBodyData = aR.getData().getBody().getData();
            resp.setImageURL(responseBodyData.getImageURL());
            return R.ok().setData(resp);
        }
        return R.error(aR.getErrorMsg());
    }

}
