package com.heyu.api.controller.imageenhan;

import com.aliyun.imageenhan20190930.models.ImitatePhotoStyleResponse;
import com.aliyun.imageenhan20190930.models.ImitatePhotoStyleResponseBody;
import com.heyu.api.alibaba.handle.imageenhan.AImitatePhotoStyleHandle;
import com.heyu.api.alibaba.request.imageenhan.AImitatePhotoStyleRequest;
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.imageenhan.ImitatePhotoStyleReq;
import com.heyu.api.resp.imageenhan.ImitatePhotoStyleResp;
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/imageenhan/2019-09-30/ImitatePhotoStyle?tab=DOC&lang=JAVA&RegionId=cn-shanghai
 *
 *
 *照图修图
 *
 * ImitatePhotoStyle
 *
 * 功能描述
 * 照图修图能力可以将输入的参考图的光照、色彩等不影响原图结构的风格迁移至目标图。 您可以在体验中心进行体验与试用。关于该接口功能的示例图如下：
 *
 */

@Slf4j
@RestController
@RequestMapping("/image")
@NotIntercept
public class ImitatePhotoStyleController extends BaseController {


    @Autowired
    private AImitatePhotoStyleHandle aImitatePhotoStyleHandle;


    @RequestMapping("/imitatePhotoStyle")
    @CacheResult
    public R imitatePhotoStyle(ImitatePhotoStyleReq req) {
        ImitatePhotoStyleResp resp = new ImitatePhotoStyleResp();

        AImitatePhotoStyleRequest request = new AImitatePhotoStyleRequest();
        request.setImageUrl(req.getImageUrl());
        request.setImageBase64(req.getImageBase64());
        request.setStyleBase64(req.getStyleBase64());
        request.setStyleUrl(req.getStyleUrl());

        ApiR<ImitatePhotoStyleResponse> aR = aImitatePhotoStyleHandle.handle(request);
        if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
            ImitatePhotoStyleResponseBody.ImitatePhotoStyleResponseBodyData responseBodyData = aR.getData().getBody().getData();
            resp.setImageURL(responseBodyData.getImageURL());
            return R.ok().setData(resp);
        }
        return R.error(aR.getErrorMsg());
    }


}
























