package com.njcn.rdms.module.project.controller.admin.status;

import com.njcn.rdms.framework.common.pojo.CommonResult;
import com.njcn.rdms.framework.common.pojo.PageResult;
import com.njcn.rdms.framework.common.util.object.BeanUtils;
import com.njcn.rdms.module.project.controller.admin.status.vo.model.ObjectStatusModelRespVO;
import com.njcn.rdms.module.project.controller.admin.status.vo.transition.ObjectStatusTransitionPageReqVO;
import com.njcn.rdms.module.project.controller.admin.status.vo.transition.ObjectStatusTransitionRespVO;
import com.njcn.rdms.module.project.controller.admin.status.vo.transition.ObjectStatusTransitionSaveReqVO;
import com.njcn.rdms.module.project.dal.dataobject.status.ObjectStatusTransitionDO;
import com.njcn.rdms.module.project.service.status.ObjectStatusTransitionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.njcn.rdms.framework.common.pojo.CommonResult.success;

/**
 * 对象状态流转管理接口。
 */
@Tag(name = "管理后台 - 对象状态流转")
@RestController
@RequestMapping("/project/status/transition")
@Validated
public class ObjectStatusTransitionController {

    @Resource
    private ObjectStatusTransitionService objectStatusTransitionService;

    @PostMapping("/create")
    @Operation(summary = "创建对象状态流转")
    public CommonResult<Long> createTransition(@Valid @RequestBody ObjectStatusTransitionSaveReqVO createReqVO) {
        return success(objectStatusTransitionService.createTransition(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "修改对象状态流转")
    public CommonResult<Boolean> updateTransition(@Valid @RequestBody ObjectStatusTransitionSaveReqVO updateReqVO) {
        objectStatusTransitionService.updateTransition(updateReqVO);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获取对象状态流转")
    @Parameter(name = "id", description = "对象状态流转Id", required = true, example = "1024")
    public CommonResult<ObjectStatusTransitionRespVO> getTransition(@RequestParam("id") Long id) {
        ObjectStatusTransitionRespVO transition = objectStatusTransitionService.getTransition(id);
        return success(BeanUtils.toBean(transition, ObjectStatusTransitionRespVO.class));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除对象状态流转")
    @Parameter(name = "id", description = "状态流转Id", required = true, example = "1024")
    public CommonResult<Boolean> deleteTransition(@RequestParam("id") Long id) {
        objectStatusTransitionService.deleteTransition(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "状态流转Id列表", required = true)
    @Operation(summary = "批量删除对象状态流转")
    public CommonResult<Boolean> deleteModelList(@RequestParam("ids") List<Long> ids) {
        objectStatusTransitionService.deleteTransitionList(ids);
        return success(true);
    }

    @GetMapping("/page")
    @Operation(summary = "获取对象状态流转分页")
    public CommonResult<PageResult<ObjectStatusTransitionRespVO>> getTransitionPage(
            @Valid ObjectStatusTransitionPageReqVO pageReqVO) {
        PageResult<ObjectStatusTransitionDO> pageResult = objectStatusTransitionService.getTransitionPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ObjectStatusTransitionRespVO.class));
    }

}
