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.ObjectStatusModelPageReqVO;
import com.njcn.rdms.module.project.controller.admin.status.vo.model.ObjectStatusModelRespVO;
import com.njcn.rdms.module.project.controller.admin.status.vo.model.ObjectStatusModelSaveReqVO;
import com.njcn.rdms.module.project.dal.dataobject.status.ObjectStatusModelDO;
import com.njcn.rdms.module.project.service.status.ObjectStatusModelService;
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.*;

import java.util.List;

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

/**
 * 对象状态模型管理接口。
 */
@Tag(name = "管理后台 - 对象状态模型")
@RestController
@RequestMapping("/project/status/model")
@Validated
public class ObjectStatusModelController {

    @Resource
    private ObjectStatusModelService objectStatusModelService;

    @PostMapping("/create")
    @Operation(summary = "创建对象状态模型")
    public CommonResult<Long> createModel(@Valid @RequestBody ObjectStatusModelSaveReqVO createReqVO) {
        return success(objectStatusModelService.createModel(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "修改对象状态模型")
    public CommonResult<Boolean> updateModel(@Valid @RequestBody ObjectStatusModelSaveReqVO updateReqVO) {
        objectStatusModelService.updateModel(updateReqVO);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获取对象状态模型")
    @Parameter(name = "id", description = "对象状态模型Id", required = true, example = "1024")
    public CommonResult<ObjectStatusModelRespVO> getModel(@RequestParam("id") Long id) {
        ObjectStatusModelRespVO model = objectStatusModelService.getModel(id);
        return success(BeanUtils.toBean(model, ObjectStatusModelRespVO.class));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除对象状态模型")
    @Parameter(name = "id", description = "对象状态模型Id", required = true, example = "1024")
    public CommonResult<Boolean> deleteModel(@RequestParam("id") Long id) {
        objectStatusModelService.deleteModel(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) {
        objectStatusModelService.deleteModelList(ids);
        return success(true);
    }

    @GetMapping("/page")
    @Operation(summary = "获取对象状态模型分页")
    public CommonResult<PageResult<ObjectStatusModelRespVO>> getModelPage(@Valid ObjectStatusModelPageReqVO pageReqVO) {
        PageResult<ObjectStatusModelDO> pageResult = objectStatusModelService.getModelPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ObjectStatusModelRespVO.class));
    }

}
