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

import com.zfire.mall.manager.bean.admin.AdminModuleBean;
import com.zfire.mall.manager.bean.admin.AdminModuleTree;
import com.zfire.mall.manager.bean.admin.AdminModuleVO;
import com.zfire.mall.manager.bean.admin.AdminWebsitTree;
import com.zfire.mall.manager.exception.RemoteServiceException;
import com.zfire.mall.manager.helper.ResponseHelper;
import com.zfire.mall.manager.logic.admin.AdminModuleLogic;
import com.zfire.mall.manager.plus.entity.AdminModule;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api(value = "系统菜单管理", tags ={"系统菜单管理"} )
@RequestMapping(value = "/admin/module", produces = "application/json; charset=utf-8")
public class AdminModuleController {

    @Autowired
    AdminModuleLogic adminModuleLogic;



    @GetMapping("/detail")
    @ApiOperation("详情")
    public ResponseHelper<AdminModuleVO> detail(@RequestParam String moduleId){
        AdminModuleVO detail = adminModuleLogic.detail(moduleId);
        return ResponseHelper.success(detail);
    }

    @PostMapping("/add")
    @ApiOperation("新增")
    public ResponseHelper add(@RequestBody AdminModuleBean adminModule){
        adminModuleLogic.add(adminModule);
        return ResponseHelper.success();
    }


    @PostMapping("/update")
    @ApiOperation("修改")
    public ResponseHelper update(@RequestBody AdminModule adminModule){
        adminModuleLogic.update(adminModule);
        return ResponseHelper.success();
    }

    @PostMapping("/delete")
    @ApiOperation("删除")
    public ResponseHelper delete(@RequestParam String id){
        adminModuleLogic.delete(id);
        return ResponseHelper.success();
    }


    @PostMapping("/favorites/save")
    @ApiOperation("常用菜单-保存")
    public ResponseHelper setupFavorites(@RequestParam List<String> adminModuleIds){
        adminModuleLogic.setupFavorites(adminModuleIds);
        return ResponseHelper.success();
    }

    @GetMapping("/favorites/list")
    @ApiOperation("常用菜单-列表")
    public ResponseHelper<List<AdminModule>> listFavorites(){
        List<AdminModule> adminModules = adminModuleLogic.listFavorites();
        return ResponseHelper.success(adminModules);
    }



}
