package com.heyu.api.controller.imageseg;


import com.aliyun.imageseg20191230.models.SegmentFoodResponse;
import com.aliyun.imageseg20191230.models.SegmentFoodResponseBody;
import com.heyu.api.alibaba.handle.imageseg.ASegmentFoodHandle;
import com.heyu.api.alibaba.request.imageseg.ASegmentFoodRequest;
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.imageseg.SegmentFoodResp;
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/SegmentFood
 *
 * 食品分割
 *
 * SegmentFood
 */
@Slf4j
@RestController
@RequestMapping("/food")
@NotIntercept
public class SegmentFoodController extends BaseController {


    @Autowired
    private ASegmentFoodHandle segmentFoodHandle;


    @RequestMapping("/segment")
    @CacheResult
    public R segment(ASegmentFoodRequest request) {
        SegmentFoodResp resp = new SegmentFoodResp();


        ApiR<SegmentFoodResponse> aR = segmentFoodHandle.handle(request);
        if (aR.isSuccess() && isSuccessStatusCode(aR.getData().getStatusCode())) {
            SegmentFoodResponseBody.SegmentFoodResponseBodyData responseBodyData = aR.getData().getBody().getData();
            resp.setImageURL(responseBodyData.getImageURL());
            return R.ok().setData(resp);
        }
        return R.error();
    }
}
