package com.ruoyi.web.controller.file;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.file.model.FileModel;
import com.ruoyi.file.model.FileSystemFilter;
import com.ruoyi.file.object.ProjectState;
import com.ruoyi.file.object.StateMachine;
import com.ruoyi.file.service.FileSystemService;
import com.ruoyi.file.service.StateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 状态Controller
 * 
 * @author zhao
 * @date 2023-10-19
 */
@Api(tags = "状态")
@RestController
@RequestMapping("/state")
public class StateController extends BaseController
{
    @Autowired
    private StateService stateService;

    /**
     * 查询项目状态列表
     */
    @ApiOperation("查询项目状态列表")
    @PreAuthorize("@ss.hasPermi('admin:state:list')")
    @GetMapping("/list")
    public AjaxResult list()
    {
        List<ProjectState> detail = stateService.list();
        return AjaxResult.success(detail);
    }

    /**
     * 查询项目状态
     */
    @ApiOperation("查询项目状态")
    @PreAuthorize("@ss.hasPermi('admin:state:detail')")
    @GetMapping("/detail/{token}")
    public AjaxResult detail(@PathVariable String token)
    {
        ProjectState detail = stateService.detail(token);
        return null != detail ? AjaxResult.success(detail) : AjaxResult.error();
    }

    /**
     * GC
     */
    @ApiOperation("GC")
    @PreAuthorize("@ss.hasPermi('admin:state:gc')")
    @PostMapping("/gc")
    public AjaxResult gc()
    {
        long count = stateService.gc();
        return AjaxResult.success(count);
    }

    /**
     * 查询状态机信息
     */
    @ApiOperation("查询状态机信息")
    @PreAuthorize("@ss.hasPermi('admin:state:machine')")
    @GetMapping("/machine")
    public AjaxResult stateMachine()
    {
        StateMachine stateMachine = stateService.stateMachine();
        return AjaxResult.success(stateMachine);
    }

    /**
     * 备份
     */
    @ApiOperation("dump")
    @PreAuthorize("@ss.hasPermi('admin:state:dump')")
    @PostMapping("/dump")
    public AjaxResult dump()
    {
        stateService.dump();
        return AjaxResult.success();
    }

}
