package org.jeecg.modules.xcx.address.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.TokenUtils;
import org.jeecg.config.shiro.ShiroRealm;
import org.jeecg.modules.hanHaiMember.entity.HanHaiMember;
import org.jeecg.modules.hoteladdress.entity.HotelAddress;
import org.jeecg.modules.xcx.address.req.AddressPageReq;
import org.jeecg.modules.xcx.address.service.IAddressService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
@Api(tags = "地址接口")
@Slf4j
@RestController
@RequestMapping("/address")
public class AddressController {

    @Resource
    private IAddressService addressService;
    @Resource
    private ShiroRealm shiroRealm;


    @ApiOperation(value = "分页", notes = "分页")
    @GetMapping("/page")
    public Result<?> addressPage(HttpServletRequest request , AddressPageReq addressPageReq){
        addressPageReq.setToken(TokenUtils.getTokenByRequest(request));
        return addressService.addressPage(addressPageReq);
    }

    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/add")
    public Result<?> addressAdd(HttpServletRequest request , HotelAddress hotelAddress){
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(TokenUtils.getTokenByRequest(request));
        hotelAddress.setUserId(hanHaiMember.getId());
        return addressService.addressAdd(hotelAddress);
    }

    @ApiOperation(value = "修改", notes = "修改")
    @PostMapping("/edit")
    public Result<?> addressEdit(HttpServletRequest request , HotelAddress hotelAddress){
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(TokenUtils.getTokenByRequest(request));
        hotelAddress.setUserId(hanHaiMember.getId());
        return addressService.addressEdit(hotelAddress);
    }

    @ApiOperation(value = "是否默认地址", notes = "是否默认地址")
    @PostMapping("/default")
    public Result<?> defaultAddress(HttpServletRequest request , String id){
        return addressService.defaultAddress(id,TokenUtils.getTokenByRequest(request));
    }

    @ApiOperation(value = "删除", notes = "删除")
    @PostMapping("/delete")
    public Result<?> deleteAddress(HttpServletRequest request , String id){
        return addressService.deleteAddress(id,TokenUtils.getTokenByRequest(request));
    }

}
