package com.njzscloud.dispose.mfg.craft.controller;

import com.njzscloud.common.core.utils.R;
import com.njzscloud.common.mp.support.PageParam;
import com.njzscloud.common.mp.support.PageResult;
import com.njzscloud.dispose.mfg.craft.pojo.entity.CraftEntity;
import com.njzscloud.dispose.mfg.craft.pojo.param.AddCraftParam;
import com.njzscloud.dispose.mfg.craft.pojo.param.SearchCraftParam;
import com.njzscloud.dispose.mfg.craft.pojo.result.SearchCraftResult;
import com.njzscloud.dispose.mfg.craft.service.CraftService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 工艺
 */
@Slf4j
@RestController
@RequestMapping("/craft")
@RequiredArgsConstructor
public class CraftController {
    private final CraftService craftService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public R<?> add(@RequestBody AddCraftParam addCraftParam) {
        craftService.add(addCraftParam);
        return R.success();
    }

    /**
     * 修改
     */
    @PostMapping("/modify")
    public R<?> modify(@RequestBody CraftEntity craftEntity) {
        craftService.modify(craftEntity);
        return R.success();
    }

    /**
     * 删除
     */
    @PostMapping("/del")
    public R<?> del(@RequestBody List<Long> ids) {
        craftService.del(ids);
        return R.success();
    }

    /**
     * 详情
     */
    @GetMapping("/detail")
    public R<SearchCraftResult> detail(@RequestParam("id") Long id) {
        return R.success(craftService.detail(id));
    }

    /**
     * 禁用/启用
     */
    @GetMapping("/disable")
    public R<?> disable(@RequestParam("id") Long id, @RequestParam("disable") Boolean disable) {
        craftService.disable(id, disable);
        return R.success();
    }

    /**
     * 分页查询
     */
    @GetMapping("/paging")
    public R<PageResult<SearchCraftResult>> paging(PageParam pageParam, SearchCraftParam searchCraftParam) {
        return R.success(craftService.paging(pageParam, searchCraftParam));
    }
}
