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

import com.fzm.mall.server.admin.constant.MallResponseError;
import com.fzm.mall.server.admin.opration.entity.dto.PopularizeCommissionSettingDTO;
import com.fzm.mall.server.admin.opration.entity.vo.PopularizeCommissionSettingVO;
import com.fzm.mall.server.admin.opration.service.IPopularizeCommissionService;
import com.fzm.mall.server.admin.repo.ResponseFactory;
import com.fzm.mall.server.admin.repo.ResponseVO;
import com.fzm.mall.server.admin.user_center.entity.dto.MemberConfigDTO;
import com.fzm.mall.server.admin.user_center.entity.vo.MemberConfigVO;
import com.fzm.mall.server.admin.user_center.service.ISysMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * @author wangp
 * @date 2021/7/19 11:06
 * @description 推广佣金
 * @since JDK 1.8
 */
@Api(tags = "运营中心-推广佣金")
@Validated
@RestController
@RequestMapping("/popularizeCommission")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PopularizeCommissionController {

    private final IPopularizeCommissionService popularizeCommissionService;
    private final ResponseFactory resFac;

    @ApiOperation("保存")
    @PostMapping("/save")
    public ResponseVO edit(@RequestBody @Valid List<PopularizeCommissionSettingDTO> dtoList) {
        if (dtoList.size() != 5) {
            return resFac.getResponse(MallResponseError.PARAM_ERROR);
        }
        popularizeCommissionService.save(dtoList);
        return resFac.getSimpleSuccessResponse();
    }

    @ApiOperation("设置列表")
    @GetMapping("/list")
    public ResponseVO list() {
        List<PopularizeCommissionSettingVO> configVOS = popularizeCommissionService.listSelfDefine();
        return resFac.getSuccessResponseWithData(configVOS);
    }

}
