package com.heyu.api.controller.face;


import com.aliyun.facebody20191230.models.LiquifyFaceRequest;
import com.aliyun.facebody20191230.models.LiquifyFaceResponse;
import com.aliyun.facebody20191230.models.LiquifyFaceResponseBody;
import com.heyu.api.alibaba.handle.facebody.ALiquifyFaceHandle;
import com.heyu.api.alibaba.request.facebody.ALiquifyFaceRequest;
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.face.LiquifyFaceReq;
import com.heyu.api.resp.face.LiquifyFaceResp;
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;

@Slf4j
@RestController
@RequestMapping("/face")
@NotIntercept
public class LiquifyFaceController extends BaseController {

    @Autowired
    private ALiquifyFaceHandle aLiquifyFaceHandle;


    @RequestMapping("/liquify")
    @CacheResult
    public R liquify(LiquifyFaceReq req) {

        LiquifyFaceResp resp = new LiquifyFaceResp();
        ALiquifyFaceRequest request = new ALiquifyFaceRequest();

        request.setSlimDegree(req.getSlimDegree());
        request.setImageBase64(req.getImageBase64());
        request.setImageUrl(req.getImageUrl());


        ApiR<LiquifyFaceResponse> aR = aLiquifyFaceHandle.handle(request);


        if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
            LiquifyFaceResponseBody.LiquifyFaceResponseBodyData responseBodyData = aR.getData().getBody().getData();

            resp.setImageURL(responseBodyData.getImageURL());
            return R.ok().setData(resp);
        }
        return R.error(aR.getErrorMsg());
    }


}
