package com.mcwl.web.controller.memberCenter;

import cn.hutool.core.bean.BeanUtil;
import com.mcwl.common.core.domain.R;
import com.mcwl.memberCenter.domain.MemberBenefit;
import com.mcwl.memberCenter.domain.dto.MemberBenefitDto;
import com.mcwl.memberCenter.domain.vo.MemberBenefitVO;
import com.mcwl.memberCenter.service.MemberBenefitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/***
 * 会员权益关联
 */
@RestController
@RequestMapping("memberBenefit")
@RequiredArgsConstructor
@Api(tags = "会员中心")
public class MemberBenefitController {

    private final MemberBenefitService memberBenefitService;


    /**
     * 获取会员等级及权益列表
     */
//    @PreAuthorize("@ss.hasPermi('system:memberBenefit:list')")
    @GetMapping("getMemberBenefitList")
    @ApiOperation(value = "获取会员等级及权益列表")
    public R<List<MemberBenefitVO>> getMemberBenefitList() {

        return R.ok(memberBenefitService.getMemberBenefitList());
    }

    /**
     * 查询会员等级权益
     */
    @ApiOperation(value = "查询会员权益")
    @GetMapping("getMemberBenefit")
    public R<MemberBenefitVO> getMemberBenefit(@Valid
                                               @NotNull(message = "会员等级id不能为空")
                                               @ApiParam(value = "会员等级id", required = true)
                                               Long memberLevelId) {

        return R.ok(memberBenefitService.getMemberBenefit(memberLevelId));
    }

    /**
     * 添加会员权益
     */
//    @PreAuthorize("@ss.hasPermi('system:memberBenefit:add')")
    @ApiOperation(value = "会员绑定权益")
    @PostMapping("addMemberBenefit")
    public R<Object> addMemberBenefit(@RequestBody @Valid MemberBenefitDto memberBenefitDto) {
        memberBenefitService.addMemberBenefit(memberBenefitDto);
        return R.ok();
    }


    //    @PreAuthorize("@ss.hasPermi('system:memberBenefit:edit')")
    @ApiOperation(value = "修改会员权益")
    @PostMapping("updateMemberBenefit")
    public R<Object> updateMemberBenefit(@RequestBody @Valid MemberBenefit memberBenefit) {

        return R.ok(memberBenefitService.updateById(memberBenefit));
    }

    @ApiOperation(value = "删除会员权益")
    @GetMapping("deleteMemberBenefit")
    public R<Object> deleteMemberBenefit(@Valid @NotNull(message = "会员权益id不能为空") Long id) {

        return R.ok(memberBenefitService.removeById(id));
    }


}
