package com.buy507.mall.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.buy507.mall.common.api.CommonPage;
import com.buy507.mall.common.api.CommonResult;
import com.buy507.mall.dto.MemberResult;
import com.buy507.mall.dto.MemberTradeRecordResult;
import com.buy507.mall.model.DmsMemberBankAccount;
import com.buy507.mall.service.UmsMemberService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@Api(tags = "UmsMemberController", description = "会员管理")
@RequestMapping("/member")
public class UmsMemberController {
	
	@Autowired
	private UmsMemberService memberService;
	
	@ApiOperation("分页查询会员信息")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<MemberResult>> list(
    		@RequestParam(value = "nickname", required = false) String nickname,
    		@RequestParam(value = "inviter", required = false) String inviter,
    		@RequestParam(value = "memberLevel", required = false) Integer memberLevel,
			@RequestParam(value = "storeStatus", required = false) Integer storeStatus,
			@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
			@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
		
		List<MemberResult> list = memberService.list(nickname, inviter, memberLevel, storeStatus, pageSize, pageNum);
        return CommonResult.success(CommonPage.restPage(list));
    }
	
	@ApiOperation("修改会员开店状态")
    @RequestMapping(value = "/update/storeStatus/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<String> updateStoreStatus(@PathVariable Long id, @RequestParam Integer storeStatus) {
		memberService.updateStoreStatus(id, storeStatus);
        return CommonResult.success(null);
    }
	
	@ApiOperation("查询会员银行信息")
    @RequestMapping(value = "/bankAccount/list", method = RequestMethod.GET)
    public CommonResult<List<DmsMemberBankAccount>> bankAccountList(
    		@RequestParam(value = "memberId", required = true) Long memberId) {
		List<DmsMemberBankAccount> list = memberService.bankAccountList(memberId);
        return CommonResult.success(list);
    }
	
	@ApiOperation("查询会员账户交易明细")
    @RequestMapping(value = "/tradeRecord/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<MemberTradeRecordResult>> tradeRecordList(
    		@RequestParam(value = "memberId", required = true) Long memberId,
    		@RequestParam(value = "orderSn", required = false) String orderSn,
    		@RequestParam(value = "itemType", required = false) Integer itemType,
    		@RequestParam(value = "type", required = false) Integer type,
    		@RequestParam(value = "pageSize", required = false) Integer pageSize,
    		@RequestParam(value = "pageNum", required = false) Integer pageNum) {
		List<MemberTradeRecordResult> list = memberService.tradeRecordList(memberId, orderSn, itemType, 
				type, pageSize, pageNum);
        return CommonResult.success(CommonPage.restPage(list));
    }
	
}
