package com.wteam.controller.passport;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wteam.framework.common.aop.annotation.DemoSite;
import com.wteam.framework.common.aop.annotation.PreventDuplicateSubmissions;
import com.wteam.framework.common.enums.ResultUtil;
import com.wteam.framework.common.vo.PageVO;
import com.wteam.framework.common.vo.ResultMessage;
import com.wteam.framework.modules.member.entity.dos.Member;
import com.wteam.framework.modules.member.entity.dto.ManagerMemberEditDTO;
import com.wteam.framework.modules.member.entity.dto.MemberAddDTO;
import com.wteam.framework.modules.member.entity.vo.MemberSearchVO;
import com.wteam.framework.modules.member.entity.vo.MemberVO;
import com.wteam.framework.modules.member.service.MemberService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 管理端,会员接口
 *
 * @author Bulbasaur
 * @since 2020-02-25 14:10:16
 */
@RestController
@Tag(name = "管理端,会员接口")
@RequestMapping("/manager/passport/member")
public class MemberManagerController {
    @Autowired
    private MemberService memberService;

    @Operation(summary = "会员分页列表")
    @GetMapping
    public ResultMessage<IPage<MemberVO>> getByPage(MemberSearchVO memberSearchVO, PageVO page) {
        return ResultUtil.data(memberService.getMemberPage(memberSearchVO, page));
    }


    @Operation(summary = "通过ID获取会员信息")
    @Parameter(name = "id", description = "会员ID", required = true, schema = @Schema(type = "string"), in =ParameterIn.PATH)
    @GetMapping(value = "/{id}")
    public ResultMessage<MemberVO> get(@PathVariable String id) {

        return ResultUtil.data(memberService.getMember(id));
    }

    @Operation(summary = "添加会员")
    @PostMapping
    public ResultMessage<Member> save(@Valid MemberAddDTO member) {

        return ResultUtil.data(memberService.addMember(member));
    }

    @DemoSite
    @PreventDuplicateSubmissions
    @Operation(summary = "修改会员基本信息")
    @PutMapping
    public ResultMessage<Member> update(@Valid ManagerMemberEditDTO managerMemberEditDTO) {
        return ResultUtil.data(memberService.updateMember(managerMemberEditDTO));
    }

    @DemoSite
    @PreventDuplicateSubmissions
    @Operation(summary = "修改会员状态,开启关闭会员")
    @Parameters({
            @Parameter(name = "memberIds", description = "会员ID", required = true, schema = @Schema(type = "array",implementation = String.class),  in = ParameterIn.QUERY),
            @Parameter(name = "disabled", required = true, schema = @Schema(type = "boolean"), in = ParameterIn.QUERY)
    })
    @PutMapping("/updateMemberStatus")
    public ResultMessage<Object> updateMemberStatus(@RequestParam List<String> memberIds, @RequestParam Boolean disabled) {
        memberService.updateMemberStatus(memberIds, disabled);
        return ResultUtil.success();
    }


    @Operation(summary = "根据条件查询会员总数")
    @GetMapping("/num")
    public ResultMessage<Long> getByPage(MemberSearchVO memberSearchVO) {
        return ResultUtil.data(memberService.getMemberNum(memberSearchVO));
    }


}
