package cn.cslg.pas.controller;

import cn.cslg.pas.common.core.annotation.Permission;
import cn.cslg.pas.common.core.base.Constants;
import cn.cslg.pas.common.utils.Response;
import cn.cslg.pas.common.utils.auth.checkAuth;
import cn.cslg.pas.domain.PatentImage;
import cn.cslg.pas.service.PatentImageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 专利附图 前端控制器
 * </p>
 *
 * @author 王岩
 * @since 2022-03-02
 */
@Tag(name = "专利附图")
@RestController
@RequestMapping(Constants.API_VERSION_V2 + "/patent/image")
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class PatentImageController {

    private final PatentImageService patentImageService;

    @checkAuth(FunId = "/workspace/details/figureUpdata")
    @PostMapping("add")
    @Operation(summary = "新增附图")
    public String add(MultipartFile file, PatentImage patentImage) {
        return patentImageService.add(file, patentImage);
    }

    @checkAuth(FunId = "/workspace/details/figuremodify")
    @PostMapping("edit")
    @Operation(summary = "编辑附图")
    public String edit(MultipartFile file, PatentImage patentImage) {
        return patentImageService.edit(file, patentImage);
    }

    @checkAuth(FunId = "/workspace/details/figureDelete")
    @PostMapping("delete")
    @Operation(summary = "删除附图")
    public String delete(Integer id) {
        patentImageService.delete(id);
        return Response.success(true);
    }
}
