package com.gree.mall.manager.controller.marketing;

import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.marketing.MarketingMaterialsGroupLogic;
import com.gree.mall.manager.plus.entity.MarketingMaterialsGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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


@Api(value = "营销素材组", tags = {"营销素材组"})
@RestController
@RequestMapping(value = "/marketing/group", produces = "application/json; charset=utf-8")
public class MarketingMaterialsGroupController {

    @Autowired
    private MarketingMaterialsGroupLogic marketingMaterialsGroupLogic;


    @ApiOperation("获取所有分组")
    @GetMapping("/list")
    public ResponseHelper<List<MarketingMaterialsGroup>> list(
            HttpServletRequest request,
            @ApiParam(value = "分组名称", required = false) @RequestParam(required = false) String groupName
    ) {
        return ResponseHelper.success(marketingMaterialsGroupLogic.list(request, groupName));
    }


    @ApiOperation("添加分组")
    @PostMapping("/add")
    public ResponseHelper<MarketingMaterialsGroup> add(
            HttpServletRequest request,
            @ApiParam(value = "分组名称", required = true) @RequestParam(required = true) String groupName
    ) {
        MarketingMaterialsGroup add = marketingMaterialsGroupLogic.add(request, groupName);
        return ResponseHelper.success(add);
    }

    @ApiOperation("修改分组名称")
    @PostMapping("/update")
    public ResponseHelper<Void> update(@ApiParam(value = "分组id", required = true) @RequestParam(required = true) String groupId,
                                       @ApiParam(value = "分组名称", required = true) @RequestParam(required = true) String groupName) {
        marketingMaterialsGroupLogic.update(groupId, groupName);
        return ResponseHelper.success();
    }


    @ApiOperation("删除分组")
    @PostMapping("/delete")
    public ResponseHelper<Void> delete(@ApiParam(value = "分组id", required = true) @RequestParam(required = true) String groupId) {

        marketingMaterialsGroupLogic.delete(groupId);
        return ResponseHelper.success();
    }

}
