package com.keyware.shandan.bianmu.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.keyware.shandan.bianmu.entity.DirectoryTableVo;
import com.keyware.shandan.bianmu.service.DirectoryTableService;
import com.keyware.shandan.common.controller.BaseController;
import com.keyware.shandan.common.entity.Result;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.Arrays;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/directory/form")
public class DirectoryTableController extends BaseController<DirectoryTableService, DirectoryTableVo, Integer> {

    @Autowired
    private DirectoryTableService directoryTableService;


    @PostMapping("/add")
    public Result<Object> addForm(Param param) {
        return Result.of(directoryTableService.addFormBatch(param.getDirId(), param.getFormIdList()));
    }

    @PostMapping("/remove")
    public Result<Object> removeForm(Param param) {
        return Result.of(directoryTableService.removeFormBatch(param.getDirId(), param.getFormIdList()));
    }

    @Data
    public static class Param {
        private String dirId;
        private String formIds;

        public String getDirId() {
            Assert.hasText(dirId, "参数错误， dirId不能为空");
            return dirId;
        }

        public List<String> getFormIdList() {
            Assert.hasText(formIds, "参数错误，formIds不能为空");
            return Arrays.asList(formIds.split(","));
        }
    }

}
