package com.ruoyi.wx.web.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.ExceptionUtil;
import com.ruoyi.wx.web.domain.vo.SaleInfoVo;
import com.ruoyi.wx.web.service.IWxHomeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.ExecutionException;

/**
 * 首页服务
 */
@RestController
@RequestMapping("/wx/home")
@Slf4j
public class WxHomeController {
    @Autowired
    private IWxHomeService wxHomeService;

//    @ApiOperation(value = "查询首页所有信息")
    @GetMapping("/index")
    public AjaxResult getIndex() {
        try {
            return wxHomeService.getIndex();
        } catch (InterruptedException | ExecutionException e) {
            return AjaxResult.error();
        }
    }

//    @ApiOperation(value = "发售信息详情", notes = "根据id查询详情内容")
    @GetMapping("/sale/info/{id}")
    public AjaxResult getSaleInfo(@PathVariable("id") Long id) {
        try {
            List<SaleInfoVo> infoList = wxHomeService.getSaleInfo(id);
            return AjaxResult.success(infoList);
        } catch (Exception e) {
            return AjaxResult.error(ExceptionUtil.getExceptionMessage(e));
        }
    }

    @GetMapping("/sale/calendar")
    public AjaxResult saleCalendar() {
        try {
            List<SaleInfoVo> infoList = wxHomeService.getSaleCalendar();
            return AjaxResult.success(infoList);
        } catch (Exception e) {
            return AjaxResult.error(ExceptionUtil.getExceptionMessage(e));
        }
    }

    @GetMapping("/thumbs/{id}")
    public AjaxResult thumbs(@PathVariable("id") Long id) {
        try {
            Long thumbs = wxHomeService.thumbs(id);
            return AjaxResult.success(thumbs);
        } catch (Exception e) {
            return AjaxResult.error(ExceptionUtil.getExceptionMessage(e));
        }
    }
}
