package com.zfire.mall.manager.controller.admin;

import com.zfire.mall.manager.bean.admin.AdminWebsitTree;
import com.zfire.mall.manager.bean.admin.respDto.AdminWebsitDto;
import com.zfire.mall.manager.exception.RemoteServiceException;
import com.zfire.mall.manager.helper.ResponseHelper;
import com.zfire.mall.manager.logic.admin.AdminWebsitLogic;
import com.zfire.mall.manager.plus.entity.AdminWebsit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@RestController
@Api(value = "部门管理API", tags ={"部门管理API"} )
@RequestMapping(value = "/admin/websit", produces = "application/json; charset=utf-8")
public class AdminWebsitController {

    @Autowired
    AdminWebsitLogic adminWebsitLogic;



    @GetMapping("/byparent")
    @ApiOperation("根据父级查询部门")
    public ResponseHelper<AdminWebsit> byParent(
            @ApiParam(value = "父id",required = true) @RequestParam String parentId
    ){
        List<AdminWebsit> adminWebsits = adminWebsitLogic.getbyParentId(parentId);
        return ResponseHelper.success(adminWebsits);
    }

    @GetMapping("/allWebsitId")
    @ApiOperation("所有部门id")
    public ResponseHelper<String> allWebsitId(@ApiParam(value = "父id",required = true) @RequestParam String parentId){

        List<String> list = adminWebsitLogic.getAllAdminWebsitIds(parentId);
        return ResponseHelper.success(list);
    }

    @GetMapping("/tree")
    @ApiOperation("部门树")
    public ResponseHelper<AdminWebsitTree> tree(HttpServletRequest request){
        List<AdminWebsitTree> tree = adminWebsitLogic.tree(request);
        return ResponseHelper.success(tree);
    }


    @PostMapping("/add")
    @ApiOperation("新增部门")
    public ResponseHelper add(@RequestBody AdminWebsitDto adminWebsit, HttpServletRequest request) throws RemoteServiceException {
        adminWebsitLogic.add(adminWebsit,request);
        return ResponseHelper.success();
    }

    @PostMapping("/update")
    @ApiOperation("修改部门")
    public ResponseHelper update(@RequestBody AdminWebsitDto adminWebsit,HttpServletRequest request) throws RemoteServiceException {
        adminWebsitLogic.update(adminWebsit,request);
        return ResponseHelper.success();
    }

    @PostMapping("/delete")
    @ApiOperation("删除部门")
    public ResponseHelper delete(@RequestParam String id, HttpServletRequest request) {
        adminWebsitLogic.delete(id,request);
        return ResponseHelper.success();
    }

    @GetMapping("/detail")
    @ApiOperation("部门详情")
    public ResponseHelper<AdminWebsitDto> detail(@RequestParam String id) {
        AdminWebsitDto detail = adminWebsitLogic.detail(id);
        return ResponseHelper.success(detail);
    }

}
