package com.ruoyi.xq.controller.app;

import cn.dev33.satoken.annotation.SaIgnore;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.PageModel;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.xq.domain.Banner;
import com.ruoyi.xq.dto.app.user.HomePageReq;
import com.ruoyi.xq.dto.app.user.vo.HomeUserListVo;
import com.ruoyi.xq.dto.app.user.vo.HomeUserVo;
import com.ruoyi.xq.service.BannerService;
import com.ruoyi.xq.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/home")
@Tag(name = "首页相关接口")
@SaIgnore
public class HomeAppController {
    @Autowired
    private UserService userService;
    @Autowired
    private BannerService bannerService;


    @PostMapping("/user/page")
    @Operation(summary = "首页查询用户-分页")
    @Log(title = "首页查询用户-分页", businessType = BusinessType.OTHER, isPrintResponseData = false,isSaveDb = false)
    public R<PageModel<HomeUserListVo>> userPage(@RequestBody HomePageReq homePageReq){
        homePageReq.initBirthdayByAge();
        Page<HomeUserListVo> vo = userService.homePage(homePageReq);
        return R.ok(PageModel.build(vo));
    }

    @GetMapping("/vip/page")
    @Operation(summary = "首页查询VIP推荐用户-分页")
    @Log(title = "首页查询VIP推荐用户-分页", businessType = BusinessType.OTHER,isPrintResponseData = false, isSaveDb = false)
    public R<List<HomeUserListVo>> vipPage(){
        List<HomeUserListVo> vo = userService.vipHomePage();
        return R.ok(vo);
    }


    @GetMapping("/user/info")
    @Operation(summary = "查询用户主页信息")
    @Log(title = "查询用户主页信息", businessType = BusinessType.OTHER,isPrintResponseData = false, isSaveDb = false)
    public R<HomeUserVo> userInfo(Long userId){
        HomeUserVo vo = userService.homeUser(userId);
        return R.ok(vo);
    }

    @GetMapping("/banner")
    @Operation(summary = "轮播图")
    public R<List<Banner>> banner(){
        List<Banner> list = bannerService.list(Wrappers.lambdaQuery(Banner.class)
                .eq(Banner::getEnableStatus, 1)
                .orderByAsc(Banner::getSort));
        return R.ok(list);
    }
}
