package com.xiaoniu.system.operation.member.controller;

import com.xiaoniu.common.core.resdata.Result;
import com.xiaoniu.common.core.resdata.RowsData;
import com.xiaoniu.common.core.vo.LabelAndValueVO;
import com.xiaoniu.system.operation.member.dto.AddMemberDTO;
import com.xiaoniu.system.operation.member.dto.EditMemberDTO;
import com.xiaoniu.system.operation.member.dto.MemberDetailsVO;
import com.xiaoniu.system.operation.member.dto.MemberListQueryDTO;
import com.xiaoniu.system.operation.member.service.ITbMemberService;
import com.xiaoniu.system.operation.member.vo.MemberListVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 会员权益说明 前端控制器
 * </p>
 *
 * @author haoxuyang
 * @since 2024-10-17 09:52:31
 */
@Tag(name = "会员权益管理")
@RestController
@RequestMapping("/member")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class TbMemberController {

    private final ITbMemberService tbMemberService;

    @Operation(summary = "会员权益列表")
    @PostMapping("/list")
    public Result<RowsData<MemberListVO>> list(@RequestBody MemberListQueryDTO dto) {
        return Result.success("查询成功", tbMemberService.memberList(dto));
    }

    @Operation(summary = "新增会员权益")
    @PostMapping("/add")
    public Result<String> add(@RequestBody @Validated AddMemberDTO dto) {
        tbMemberService.addMember(dto);
        return Result.success("操作成功");
    }

    @Operation(summary = "修改会员权益")
    @PostMapping("/edit")
    public Result<String> edit(@RequestBody @Validated EditMemberDTO dto) {
        tbMemberService.editMember(dto);
        return Result.success("操作成功");
    }

    @Operation(summary = "会员权益详情")
    @GetMapping("/details")
    public Result<MemberDetailsVO> details(@RequestParam Long id) {
        return Result.success("查询成功", tbMemberService.details(id));
    }

    @Operation(summary = "删除会员权益")
    @GetMapping("/del")
    public Result<String> delMember(@RequestParam Long id) {
        tbMemberService.delMember(id);
        return Result.success("操作成功");
    }

    @Operation(summary = "获取会员列表下拉选")
    @GetMapping("/memberList")
    public Result<List<LabelAndValueVO>> getMemberList(@RequestParam(required = false) String memberName) {
        return Result.success("操作成功", tbMemberService.getMemberList(memberName));
    }

}
