package com.fzm.mall.server.admin.marketing.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.home_page.model.Admin;
import com.fzm.mall.server.admin.home_page.service.IAdminService;
import com.fzm.mall.server.admin.marketing.entity.dto.MemberIntegralRecurrenceDTO;
import com.fzm.mall.server.admin.marketing.service.IMemberIntegralRecurrenceService;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * <p>
 * 运营中心-积分返现 前端控制器
 * </p>
 *
 * @author wlx
 * @since 2021-06-04
 */
@Api(tags = "运营中心")
@Validated
@RestController
@RequestMapping("/memberIntegralRecurrence/recurrencePermission")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class MemberIntegralRecurrenceController {

    private final IMemberIntegralRecurrenceService recurrenceService;
    private final IAdminService adminService;
    private final ResponseFactory resFac;

    @ApiOperation(value = "运营中心-积分返现-编辑")
    @ApiOperationSupport(order = 1)
    @AdminLog(description = "运营中心-积分返现-编辑", module = OperateModuleEnum.OPERATE_CENTER, opType = OperateTypeEnum.UPDATE)
    @PutMapping("/update")
    public ResponseVO update(@RequestBody @Valid List<MemberIntegralRecurrenceDTO> paramList,
                             @ApiParam(value = "管理员id", required = true) @RequestHeader String adminId) {
        Admin admin = adminService.getByAdminId(adminId);

        recurrenceService.update(paramList, admin.getMerchantId());
        return resFac.getSimpleSuccessResponse();
    }

    @ApiOperation(value = "运营中心-积分返现-列表查询")
    @ApiOperationSupport(order = 2)
    @GetMapping("/list")
    public ResponseVO list(@ApiParam(value = "管理员id", required = true) @RequestHeader String adminId) {

        Admin admin = adminService.getByAdminId(adminId);
        List<MemberIntegralRecurrenceDTO> result = recurrenceService.listAll(admin.getMerchantId());
        return resFac.getSuccessResponseWithData(result);
    }
}
