package com.mcwl.web.controller.memberCenter;

import cn.hutool.core.bean.BeanUtil;
import com.mcwl.common.core.domain.R;
import com.mcwl.memberCenter.domain.Benefit;
import com.mcwl.memberCenter.domain.BenefitName;
import com.mcwl.memberCenter.domain.dto.AddBenefitDto;
import com.mcwl.memberCenter.domain.dto.AddBenefitNameDto;
import com.mcwl.memberCenter.domain.dto.EditBenefitDto;
import com.mcwl.memberCenter.domain.dto.EditBenefitNameDto;
import com.mcwl.memberCenter.domain.vo.BenefitVo;
import com.mcwl.memberCenter.service.BenefitNameService;
import com.mcwl.memberCenter.service.BenefitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

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

/***
 * 权益名称
 */
@RestController
@RequestMapping("benefitName")
@RequiredArgsConstructor
@Api(tags = "会员中心")
public class BenefitNameController {

    private final BenefitNameService benefitNameService;


    /**
     * 权益名称列表
     */
    @ApiOperation(value = "权益名称列表")
    @GetMapping("list")
    public R<List<BenefitName>> list() {
        List<BenefitName> list = benefitNameService.list();
        return R.ok(list);
    }

    @ApiOperation(value = "添加权益名称")
    @PostMapping("add")
    public R<Object> add(@RequestBody @Valid AddBenefitNameDto addBenefitDto) {
        BenefitName benefitName = BeanUtil.toBean(addBenefitDto, BenefitName.class);
        benefitNameService.save(benefitName);
        return R.ok();
    }

    @ApiOperation(value = "修改权益名称")
    @PostMapping("update")
    public R<Object> update(@RequestBody @Valid EditBenefitNameDto editBenefitNameDto) {
        BenefitName benefitName = BeanUtil.toBean(editBenefitNameDto, BenefitName.class);
        benefitNameService.updateById(benefitName);
        return R.ok();
    }

    @ApiOperation(value = "删除权益名称")
    @GetMapping("delete")
    public R<Object> delete(@Valid @NotNull(message = "id不能为空") Long id) {
        benefitNameService.removeById(id);
        return R.ok();
    }


}
