package vip.xiaonuo.disk.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.disk.domain.CapacityReAuditInfo;
import vip.xiaonuo.disk.dto.storage.GetUserStorageDTO;
import vip.xiaonuo.disk.service.IStorageReService;
import vip.xiaonuo.disk.util.TableDataInfo;
import vip.xiaonuo.disk.vo.storage.CapacityReAuditInfoVo;
import vip.xiaonuo.disk.vo.storage.StorageReBeanVO;

import javax.annotation.Resource;
@RestController
@Slf4j
public class StorageReController {

    @Resource
    private IStorageReService storageReService;


    /**
     * 查询当前默认创建空间大小 单位MB
     *
     * @return 默认创建空间大小
     */
    @GetMapping("/storagere/getDefaultStorage")
    public CommonResult<Long> getDefaultStorage() {
        return storageReService.getDefaultStorage();
    }

    /**
     * 修改当前默认创建空间大小 单位MB
     *
     * @return 修改结果
     */
    @GetMapping("/storagere/updateDefaultStorage")
    public CommonResult<String> updateDefaultStorage(@RequestParam(value = "size") Long size) {
        return storageReService.updateDefaultStorage(size);
    }


    /**
     * 查询所有用户的存储空间大小 单位MB
     *
     * @param getUserStorageDTO 查询条件
     * @return 所有用户的存储空间大小
     */
    @PostMapping("/storagere/getUserStorageList")
    public CommonResult<TableDataInfo<StorageReBeanVO>> getUserStorageList(@RequestBody GetUserStorageDTO getUserStorageDTO) {
        return storageReService.getUserStorageList(getUserStorageDTO);
    }

    /**
     * 更改用户的存储空间大小 单位MB
     *
     * @param getUserStorageDTO 更改条件
     * @return 更改结果
     */
    @PostMapping("/storagere/updateUserStorage")
    public CommonResult<String> updateUserStorage(@RequestBody GetUserStorageDTO getUserStorageDTO) {
        return storageReService.updateUserStorage(getUserStorageDTO);
    }


    /**
     * 用户查看自己的存储空间大小 单位MB
     *
     * @return 用户存储空间大小
     */
    @GetMapping("/storagere/getUserStorage")
    public CommonResult<Long> getUserStorage() {
        return storageReService.getUserStorage();
    }


    /**
     * 提交改变存储空间大小的申请
     *
     * @param  capacityReAuditInfo
     * @return 提交结果
     */
    @PostMapping("/storagere/applyChangeStorage")
    public CommonResult<String> applyChangeStorage(@RequestBody CapacityReAuditInfo capacityReAuditInfo) {
        return storageReService.applyChangeStorage(capacityReAuditInfo);
    }

    /**
     * 查询存储空间大小变更申请列表
     *
     * @param auditState         申请状态 0待审核 1审核通过 2拒绝
     * @param pageNum            页码
     * @param pageSize           页大小
     * @param usernameOrNickname 用户名或昵称
     * @return 存储空间大小变更申请列表
     */
    @GetMapping("/storagere/getCapacityAuditList")
    public CommonResult<TableDataInfo<CapacityReAuditInfoVo>> getCapacityAuditList(@RequestParam(value = "pageNum") Integer pageNum,
                                                                                   @RequestParam(value = "pageSize") Integer pageSize,
                                                                                   @RequestParam(value = "auditState", required = false) Integer auditState,
                                                                                   @RequestParam(value = "usernameOrNickname", required = false) String usernameOrNickname) {
        return storageReService.getCapacityAuditList(pageNum, pageSize, auditState, usernameOrNickname);
    }

    /**
     * 查询存储空间大小变更申请详情
     *
     * @param id 申请ID
     * @return 申请详情
     */
    @GetMapping("/storagere/getCapacityAuditDetail")
    public CommonResult<CapacityReAuditInfoVo> getCapacityAuditDetail(@RequestParam(value = "id") String id) {
        return storageReService.getCapacityAuditDetail(id);
    }


    /**
     * 审核扩容申请
     *
     * @param id           申请ID
     * @param auditState   审核状态
     * @param rejectReason 拒绝原因
     * @return 审核结果
     */
    @GetMapping("/storagere/auditCapacityAudit")
    public CommonResult<String> auditCapacityAudit(@RequestParam(value = "id") String id,
                                                   @RequestParam(value = "auditState") Integer auditState,
                                                   @RequestParam(value = "rejectReason", required = false) String rejectReason) {
        return storageReService.auditCapacityAudit(id, auditState, rejectReason);
    }


    /**
     * 用户查看自己申请记录列表
     *
     * @param pageNum    页码
     * @param pageSize   页大小
     * @param auditState 申请状态 0待审核 1审核通过 2拒绝
     * @return 申请记录列表
     */
    @GetMapping("/storagere/getUserCapacityAuditList")
    public CommonResult<TableDataInfo<CapacityReAuditInfoVo>> getUserCapacityAuditList(@RequestParam(value = "pageNum") Integer pageNum,
                                                                                     @RequestParam(value = "pageSize") Integer pageSize,
                                                                                     @RequestParam(value = "auditState", required = false) Integer auditState) {
        return storageReService.getUserCapacityAuditList(pageNum, pageSize, auditState);
    }
}