package com.fzm.mall.server.admin.system.controller;


import com.fzm.mall.server.admin.annotation.AdminLog;
import com.fzm.mall.server.admin.enums.log.OperateModuleEnum;
import com.fzm.mall.server.admin.enums.log.OperateTypeEnum;
import com.fzm.mall.server.admin.repo.ResponseFactory;
import com.fzm.mall.server.admin.repo.ResponseVO;
import com.fzm.mall.server.admin.system.entity.dto.SysNavigationDTO;
import com.fzm.mall.server.admin.system.entity.dto.SysNavigationSaveDTO;
import com.fzm.mall.server.admin.system.entity.dto.SysNavigationUpdateDTO;
import com.fzm.mall.server.admin.system.service.ISysNavigationService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 系统中心-常见问题-导航 前端控制器
 * </p>
 *
 * @author fzm
 * @since 2021-03-29
 */
@Api(tags = "系统中心")
@RestController
@RequestMapping("/sys-navigation")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SysNavigationController {

    private final ISysNavigationService navigationService;
    private final ResponseFactory resFac;

    @ApiOperation(value = "系统中心-导航-新增")
    @ApiOperationSupport(order = 1)
    @AdminLog(description = "系统中心-导航-新增", module = OperateModuleEnum.SYSTEM_CENTER, opType = OperateTypeEnum.ADD)
    @PostMapping("/save")
    public ResponseVO save(@RequestBody @Valid SysNavigationSaveDTO navigationSaveDTO) {

        navigationService.save(navigationSaveDTO);
        return resFac.getSimpleSuccessResponse();
    }

    @ApiOperation(value = "系统中心-导航-编辑")
    @ApiOperationSupport(order = 2)
    @AdminLog(description = "系统中心-导航-编辑", module = OperateModuleEnum.SYSTEM_CENTER, opType = OperateTypeEnum.UPDATE)
    @PutMapping("/update")
    public ResponseVO update(@RequestBody @Valid SysNavigationUpdateDTO navigationUpdateDTO) {

        navigationService.update(navigationUpdateDTO);
        return resFac.getSimpleSuccessResponse();
    }

    @ApiOperation(value = "系统中心-导航-删除")
    @ApiOperationSupport(order = 3)
    @AdminLog(description = "系统中心-导航-删除", module = OperateModuleEnum.SYSTEM_CENTER, opType = OperateTypeEnum.DELETE)
    @DeleteMapping("/delete/{navigationId}")
    public ResponseVO delete(
            @ApiParam(value = "navigationId", required = true) @PathVariable(value = "navigationId") String navigationId) {
        navigationService.delete(navigationId);
        return resFac.getSimpleSuccessResponse();
    }

    @ApiOperation(value = "系统中心-导航-主键查询")
    @ApiOperationSupport(order = 4)
    @GetMapping("/{navigationId}")
    public ResponseVO<SysNavigationDTO> read(
            @ApiParam(value = "navigationId", required = true) @PathVariable(value = "navigationId") String navigationId) {
        SysNavigationDTO result = navigationService.read(navigationId);
        return resFac.getSuccessResponseWithData(result);
    }

    @ApiOperation(value = "系统中心-导航-列表查询")
    @ApiOperationSupport(order = 5)
    @GetMapping("/list")
    public ResponseVO list() {
        List<SysNavigationDTO> result = navigationService.listAll();
        return resFac.getSuccessResponseWithData(result);
    }
}
