package com.ningdatech.carapi.analysis.controller;


import com.ningdatech.basic.model.PageVo;
import com.ningdatech.carapi.analysis.entity.req.IndustryStandardsListReq;
import com.ningdatech.carapi.analysis.entity.req.IndustryStandardsSaveReq;
import com.ningdatech.carapi.analysis.entity.vo.IndustryStandardsListVo;
import com.ningdatech.carapi.analysis.manage.IndustryStandardsManage;
import com.ningdatech.carapi.user.security.auth.model.UserInfoDetails;
import com.ningdatech.carapi.user.util.LoginUserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author WendyYang
 * @since 2022-10-15
 */
@Api(tags = "分析评估-行业规范")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/analysis-eval/industry-standards")
public class IndustryStandardsController {

    private final IndustryStandardsManage industryStandardsManage;

    @GetMapping("/list")
    @ApiOperation("行业规范列表")
    public PageVo<IndustryStandardsListVo> industryStandardsList(@Valid IndustryStandardsListReq req) {
        return industryStandardsManage.list(req);
    }

    @PostMapping("/save")
    @ApiOperation("新增行业规范")
    public void save(@Valid @RequestBody IndustryStandardsSaveReq req) {
        industryStandardsManage.save(req);
    }

    @ApiOperation("增加下载次数")
    @GetMapping("/incrementDownCount/{id}")
    public void incrementDownCount(@PathVariable Long id) {
        industryStandardsManage.incrementDownCount(id);
    }

    @ApiOperation("删除行业标准文件")
    @DeleteMapping("/delete-standards")
    public void deleteStandardFile(@RequestParam Long id) {
        UserInfoDetails userInfoDetails = LoginUserUtil.loginUserDetail();
        Long roleId = userInfoDetails.getRoleId();
        industryStandardsManage.deleteStandardFile(id,roleId);
    }
}
