package vip.xiaonuo.disk.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qiwenshare.common.result.RestResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.disk.domain.CapacityAuditInfo;
import vip.xiaonuo.disk.domain.StorageBean;
import vip.xiaonuo.disk.dto.storage.GetUserStorageDTO;
import vip.xiaonuo.disk.service.IStorageService;
import vip.xiaonuo.disk.util.TableDataInfo;
import vip.xiaonuo.disk.vo.storage.CapacityAuditInfoVo;
import vip.xiaonuo.disk.vo.storage.StorageBeanVO;

import javax.annotation.Resource;
import java.util.List;

/**
 * 存储空间 controller
 *
 * @author jinjilong
 */
@RestController
@Slf4j
public class StorageController {

    @Resource
    private IStorageService storageService;


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

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


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

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


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


    /**
     * 提交改变存储空间大小的申请
     *
     * @param capacityAuditInfo 申请信息
     *
     * @return 提交结果
     */
    @PostMapping("/storage/applyChangeStorage")
    public CommonResult<String> applyChangeStorage(@RequestBody CapacityAuditInfo capacityAuditInfo) {
        return storageService.applyChangeStorage(capacityAuditInfo);
    }

    /**
     * 查询存储空间大小变更申请列表
     *
     * @param auditState 申请状态 0待审核 1审核通过 2拒绝
     * @param pageNum 页码
     * @param pageSize 页大小
     * @param usernameOrNickname 用户名或昵称
     *
     * @return 存储空间大小变更申请列表
     */
    @GetMapping("/storage/getCapacityAuditList")
    public CommonResult<TableDataInfo<CapacityAuditInfoVo>> 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 storageService.getCapacityAuditList(pageNum, pageSize, auditState, usernameOrNickname);
    }

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


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


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



}
