package com.buy507.mall.portal.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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.buy507.mall.common.api.CommonResult;
import com.buy507.mall.model.UmsMemberReceiveAddress;
import com.buy507.mall.portal.domain.AreaOptions;
import com.buy507.mall.portal.service.UmsMemberReceiveAddressService;

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

/**
 * 会员收货地址管理Controller
 */
@RestController
@Api(tags = "UmsMemberReceiveAddressController", description = "会员收货地址管理")
@RequestMapping("/member/address")
public class UmsMemberReceiveAddressController {
	
    @Autowired
    private UmsMemberReceiveAddressService memberReceiveAddressService;

    @ApiOperation("添加收货地址")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public CommonResult add(@RequestBody UmsMemberReceiveAddress address) {
    	return memberReceiveAddressService.add(address);
    }

    @ApiOperation("删除收货地址")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
    public CommonResult delete(@PathVariable Long id) {
        return memberReceiveAddressService.delete(id);
    }

    @ApiOperation("修改收货地址")
    @RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
    public CommonResult update(@PathVariable Long id, @RequestBody UmsMemberReceiveAddress address) {
    	return memberReceiveAddressService.update(id, address);
    }

    @ApiOperation("显示所有收货地址")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<List<UmsMemberReceiveAddress>> list() {
        List<UmsMemberReceiveAddress> addressList = memberReceiveAddressService.list();
        return CommonResult.success(addressList);
    }
    
    @ApiOperation("获取用户默认收货地址")
    @RequestMapping(value = "/getDefaultReceivingAddress", method = RequestMethod.GET)
    public CommonResult<UmsMemberReceiveAddress> getDefaultReceivingAddress() {
        UmsMemberReceiveAddress defaultReceivingAddress = memberReceiveAddressService.getDefaultReceivingAddress();
        return CommonResult.success(defaultReceivingAddress);
    }
    
    @ApiOperation("获取单个收货地址")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public CommonResult<UmsMemberReceiveAddress> get(@PathVariable Long id) {
        UmsMemberReceiveAddress address = memberReceiveAddressService.get(id);
        return CommonResult.success(address);
    }
    
    @ApiOperation("获取所有地区信息")
	@RequestMapping(value = "/getAllArea", method = RequestMethod.GET)
	public CommonResult<List<AreaOptions>> getAllArea() {
		List<AreaOptions> areaList = memberReceiveAddressService.getAllArea();
		return CommonResult.success(areaList);
	}
    
}
