package com.sonic.shark.controller.api;

import com.sonic.common.auth.IgnoreAuth;
import com.sonic.common.rpc.Result;
import com.sonic.sdk.api.annotation.InternalRpc;
import com.sonic.shark.lib.input.BlurryRecordInput;
import com.sonic.shark.lib.input.CopyAndBlurryImgInput;
import com.sonic.shark.lib.output.BlurryRecordOutput;
import com.sonic.shark.lib.output.CopyAndBlurryImgOutput;
import com.sonic.shark.service.BlurryImgRecordService;
import com.sonic.shark.service.CopyAndBlurryImgService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 图片模糊处理
 * @Author code
 */
@InternalRpc(path = "/api/**")
@RestController
@Slf4j
public class CopyAndBlurryImgApi {

    @Autowired
    private CopyAndBlurryImgService copyAndBlurryImgService;
    @Autowired
    private BlurryImgRecordService blurryImgRecordService;

    @IgnoreAuth
    @ApiOperation(value = "拷贝并生成模糊图片访问地址", tags = {"API-图片处理"})
    @PostMapping(value = "/api/img/copy-and-blurry")
    public Result<List<CopyAndBlurryImgOutput>> copyAndBlurryImg(@Validated @RequestBody List<CopyAndBlurryImgInput> inputList) throws Exception {
        return Result.success(copyAndBlurryImgService.copyAndBlurryImg(inputList));
    }

    @IgnoreAuth
    @ApiOperation(value = "查询模糊图片访问地址", tags = {"API-图片处理"})
    @PostMapping(value = "/api/img/blurry-record-list")
    public Result<List<BlurryRecordOutput>> copyAndBlurryImg(@Validated @RequestBody BlurryRecordInput input) {
        return Result.success(blurryImgRecordService.queryBlurryImgList(input.getBizType(), input.getBizIdList(), input.getImgUrlBl()));
    }

}
