package com.yonge.cooleshow.student.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
import com.yonge.cooleshow.auth.api.entity.SysUser;
import com.yonge.toolset.base.page.PageInfo;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import com.yonge.toolset.mybatis.support.PageUtil;

import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import com.yonge.cooleshow.biz.dal.vo.VipCardRecordVo;
import com.yonge.cooleshow.biz.dal.dto.search.VipCardRecordSearch;
import com.yonge.cooleshow.biz.dal.service.VipCardRecordService;

@RestController
@RequestMapping("/vipCardRecord")
@Api(value = "购买会员卡记录表", tags = "购买会员卡记录表")
public class VipCardRecordController extends BaseController {

    @Autowired
    private VipCardRecordService vipCardRecordService;

    @Autowired
    private SysUserFeignService sysUserFeignService;

    /**
     * 查询单条
     */
    @GetMapping("/detail/{orderDetilId}")
    @ApiOperation(value = "详情", notes = "传入订单详情id")
    public HttpResponseResult<VipCardRecordVo> detail(@PathVariable("orderDetilId") Long orderDetilId) {
        SysUser user = sysUserFeignService.queryUserInfo();
        if (user == null || null == user.getId()) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        return succeed(vipCardRecordService.detail(orderDetilId, user.getId()));
    }

    /**
     * 查询分页
     */
    @PostMapping("/page")
    @ApiOperation(value = "查询分页", notes = "传入vipCardRecordSearch")
    public HttpResponseResult<PageInfo<VipCardRecordVo>> page(@RequestBody VipCardRecordSearch query) {
        SysUser user = sysUserFeignService.queryUserInfo();
        if (user == null || null == user.getId()) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        IPage<VipCardRecordVo> pages = vipCardRecordService.selectPage(PageUtil.getPage(query), query);
        return succeed(PageUtil.pageInfo(pages));
    }
}