package com.cf.imes.module.system.controller.admin.setting;


import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.operatelog.core.annotations.OperateLog;
import com.cf.imes.module.system.controller.admin.setting.vo.PackageConfigReqVO;
import com.cf.imes.module.system.dal.dataobject.setting.PackageConfigDO;
import com.cf.imes.module.system.service.setting.SettingService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;

import static com.cf.imes.framework.common.pojo.CommonResult.success;
import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.CREATE;
import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.UPDATE;

@Tag(name = "管理后台 - 系统打包配置")
@RestController
@RequestMapping("/system/setting")
@Validated
public class SettingController {


    @Resource
    private SettingService settingService;



    @PutMapping("/insert")
    @Operation(summary = "新增打包系统配置")
    @OperateLog(module="管理后台 - 系统打包配置",name = "新增打包/预打包系统配置",type = CREATE)
    //@PreAuthorize("@ss.hasPermission('system:data-source:query')")
    public CommonResult<Long> insertSetting( @RequestBody PackageConfigReqVO reqVO ) {

        return success(settingService.insertSetting(reqVO));


    }



    @PostMapping("/update")
    @Operation(summary = "更新打包系统配置")
    @OperateLog(module="管理后台 - 系统打包配置",name = "更新打包/预打包系统配置",type = UPDATE)
    @PreAuthorize("@ss.hasAnyPermissions('manage:pack:pack-config','manage:pack:pre-pack-config')")
    public CommonResult<Long> updateSetting( @RequestBody PackageConfigReqVO reqVO ) {

        return success(settingService.updateSetting(reqVO));


    }


    @GetMapping("/select")
    @Operation(summary = "查看当前用户的打包配置信息")
    @Parameter(name = "type", description = "配置类型", required = true)
    @PreAuthorize("@ss.hasAnyPermissions('manage:pack:query')")
    public CommonResult<PackageConfigDO> selectSetting(@RequestParam("type") Integer type ) {

        return success(settingService.selectSetting(type));

    }

}
