package com.fzm.mall.server.admin.opration.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.opration.entity.dto.KeywordDTO;
import com.fzm.mall.server.admin.opration.entity.dto.KeywordSaveDTO;
import com.fzm.mall.server.admin.opration.service.IKeywordService;
import com.fzm.mall.server.admin.repo.ResponseFactory;
import com.fzm.mall.server.admin.repo.ResponseVO;
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 wulixian
 * @since 2021-03-22
 */
@Api(tags = "运营中心")
@RestController
@RequestMapping("/keyword/keywordPermission")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class KeywordController {

    private final IKeywordService keywordService;
    private final ResponseFactory resFac;

    @ApiOperation(value = "运营中心-关键字-新增")
    @ApiOperationSupport(order = 1)
    @AdminLog(description = "运营中心-关键字-新增", module = OperateModuleEnum.OPERATE_CENTER, opType = OperateTypeEnum.ADD)
    @PostMapping("/save")
    public ResponseVO save(@RequestBody @Valid KeywordSaveDTO keywordSaveDTO) {
        keywordService.save(keywordSaveDTO);
        return resFac.getSimpleSuccessResponse();
    }

    @ApiOperation(value = "运营中心-关键字-删除")
    @ApiOperationSupport(order = 3)
    @AdminLog(description = "运营中心-关键字-删除", module = OperateModuleEnum.OPERATE_CENTER, opType = OperateTypeEnum.DELETE)
    @DeleteMapping("/delete/{operationKeywordId}")
    public ResponseVO delete(
            @ApiParam(value = "关键字编号", required = true) @PathVariable(value = "operationKeywordId") String operationKeywordId) {
        keywordService.delete(operationKeywordId);
        return resFac.getSimpleSuccessResponse();
    }

    @ApiOperation(value = "运营中心-关键字-列表查询")
    @ApiOperationSupport(order = 5)
    @GetMapping("/list")
    public ResponseVO list() {

        List<KeywordDTO> result = keywordService.listAll();
        return resFac.getSuccessResponseWithData(result);
    }
}
