package com.njzscloud.common.sn;

import com.njzscloud.common.core.utils.R;
import com.njzscloud.common.mp.support.PageParam;
import com.njzscloud.common.mp.support.PageResult;
import com.njzscloud.common.sn.support.SnUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 编码配置表
 */
@Slf4j
@RestController
@RequestMapping("/sys_sn_config")
@RequiredArgsConstructor
public class SnConfigController {

    private final SnConfigService snConfigService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public R<?> add(@Validated @RequestBody AddSnConfigParam addSnConfigParam) {
        snConfigService.add(addSnConfigParam);
        return R.success();
    }

    @GetMapping("/next")
    public R<?> next(@RequestParam(required = false, defaultValue = "Default") String sncode,
                     @RequestParam(required = false) String pici) {
        return R.success(SnUtil.next(sncode, pici));
    }

    @GetMapping("/reset")
    public R<?> reset(@RequestParam("sncode") String sncode) {
        snConfigService.reset(sncode);
        return R.success();
    }

    /**
     * 修改
     *
     * @param sysSnConfigEntity 数据
     */
    @PostMapping("/modify")
    public R<?> modify(@RequestBody ModifySnConfigParam modifySnConfigParam) {
        snConfigService.modify(modifySnConfigParam);
        return R.success();
    }

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

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

    /**
     * 分页查询
     */
    @GetMapping("/paging")
    public R<PageResult<SearchSnConfigResult>> paging(PageParam pageParam, SnConfigEntity snConfigEntity) {
        return R.success(snConfigService.paging(pageParam, snConfigEntity));
    }

}
