package com.heyu.api.controller.imageenhan;


import com.aliyun.imageenhan20190930.models.ExtendImageStyleResponse;
import com.aliyun.imageenhan20190930.models.ExtendImageStyleResponseBody;
import com.heyu.api.alibaba.handle.imageenhan.AExtendImageStyleHandle;
import com.heyu.api.alibaba.request.imageenhan.AExtendImageStyleRequest;
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.resp.imageenhan.ExtendImageStyleResp;
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/ExtendImageStyle?lang=JAVA&RegionId=cn-shanghai&tab=DOC
 *
 * 风格迁移
 *
 * ExtendImageStyle
 *
 *
 * 功能描述
 * 风格迁移能力可以对输入图像的风格进行转换，使得图像的色彩、笔触等视觉风格发生转化。 关于该接口功能的示例图如下：
 *
 *
 *
 */
@Slf4j
@RestController
@RequestMapping("/image")
@NotIntercept
public class ExtendImageStyleController extends BaseController {

    @Autowired
    private AExtendImageStyleHandle aExtendImageStyleHandle;


    @RequestMapping("/extendStyle")
    @CacheResult
    public R extendStyle(AExtendImageStyleRequest req) {
        ExtendImageStyleResp resp = new ExtendImageStyleResp();

        ApiR<ExtendImageStyleResponse> aR = aExtendImageStyleHandle.handle(req);
        if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
            ExtendImageStyleResponseBody.ExtendImageStyleResponseBodyData responseBodyData = aR.getData().getBody().getData();
            resp.setImageURL(responseBodyData.getUrl());
            return R.ok().setData(resp);
        }
        return R.error(aR.getErrorMsg());
    }
}
