package cn.com.ty.lift.ud.userRebate.controller;

import cn.com.ty.lift.ud.common.BaseController;
import cn.com.ty.lift.ud.userRebate.controller.query.UserRebateQuery;
import cn.com.ty.lift.ud.userRebate.mapper.entity.UserRebateEntity;
import cn.com.ty.lift.ud.userRebate.service.IUserRebateService;
import cn.com.xwy.boot.web.dto.RestResponse;
import com.baomidou.mybatisplus.extension.service.IService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 个人返利记录 API - 小陶
 * 
 * @author Xson
 * @date 2020-05-19
 */
@Api(tags = "个人返利记录 API - 小陶")
@RestController
@RequestMapping("/api/userRebates")
public class UserRebateController extends BaseController<UserRebateEntity,UserRebateQuery> {

    private final Logger log = LoggerFactory.getLogger(UserRebateController.class);
    
    private @Autowired IUserRebateService userRebateService;

    @Override
    protected IService<UserRebateEntity> getService() {
        return userRebateService;
    }

    /**
     * 邀请其他人成为下线
     * @param entity
     * @return
     */
    @PostMapping("/insert")
    @ApiOperation(value = "邀请其他人成为下线")
    @Override
    public RestResponse create(@RequestBody UserRebateEntity entity) {
        if(null == entity.getUserId()){
            return RestResponse.fail("用户不能为空");
        }
        if(null == entity.getLowerUserId()){
            return RestResponse.fail("下一级用户不能为空");
        }
        if(entity.getUserId().equals(entity.getLowerUserId())){
            return RestResponse.fail("不能邀请自己");
        }
        return userRebateService.create(entity);

    }

    /**
     * app查询个人返利信息
     * @param id
     * @return
     */
    @PostMapping("/getAllRebate/{id}")
    @ApiOperation(value = "app查询个人返利信息")
    public RestResponse getAllRebate(@PathVariable("id") Long  id) {
        return userRebateService.getAllRebate(id);

    }


    /**
     * 后台查询个人返利信息
     * @param id
     * @return
     */
    @PostMapping("/getAllRebateOfWeb/{id}")
    @ApiOperation(value = "后台查询个人返利信息")
    public RestResponse getAllRebateOfWeb(@PathVariable("id") Long  id) {
        return userRebateService.getAllRebateOfWeb(id);

    }

    /**
     * 判断是否是专家或者VIP
     * @param id
     * @return
     */
    @PostMapping("/isVipOrExpert/{id}")
    @ApiOperation(value = "判断是否是专家或者VIP")
    public RestResponse isVipOrExpert(@PathVariable("id") Long  id) {
        return userRebateService.isVipOrExpert(id);

    }
}