package com.ruoyi.cai.controller.app;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.cai.domain.Banner;
import com.ruoyi.cai.dto.app.query.index.AnchorListQuery;
import com.ruoyi.cai.dto.app.query.index.GreetQuery;
import com.ruoyi.cai.dto.app.query.index.UserQuery;
import com.ruoyi.cai.dto.app.vo.AnchorListVo;
import com.ruoyi.cai.dto.app.vo.IndexBannerVo;
import com.ruoyi.cai.dto.app.vo.user.UserInfoVo;
import com.ruoyi.cai.dto.app.vo.user.UserListVo;
import com.ruoyi.cai.dto.app.vo.index.GuardListPageVo;
import com.ruoyi.cai.dto.app.vo.index.UserGiftIndexVo;
import com.ruoyi.cai.service.*;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.BeanConvertUtil;
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.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/api/index")
@Tag(name = "首页展示相关接口")
public class IndexController {

    @Autowired
    private AnchorService anchorService;
    @Autowired
    private UserService userService;
    @Autowired
    private BannerService bannerService;
    @Autowired
    private GuardTotalService guardTotalService;
    @Autowired
    private UserGiftService userGiftService;

    @GetMapping("/banner")
    @Operation(summary = "获取首页banner图")
    public R<List<IndexBannerVo>> banner(){
        List<Banner> res = bannerService.index();
        return R.ok(BeanConvertUtil.convertListTo(res, IndexBannerVo::new));
    }

    @GetMapping("/anchor/page")
    @Operation(summary = "首页查询主播接口-分页")
    public TableDataInfo<AnchorListVo> page(PageQuery page, AnchorListQuery query){
        Page<AnchorListVo> res = anchorService.pageApp(page,query);
        return TableDataInfo.build(res);
    }

    @GetMapping("/user/page")
    @Operation(summary = "首页用户搜索接口-分页")
    public TableDataInfo<UserListVo> page(PageQuery page, UserQuery query){
        Page<UserListVo> res = userService.pageApp(page,query);
        return TableDataInfo.build(res);
    }

    @GetMapping("/user/greet/page")
    @Operation(summary = "群打招呼界面-用户搜索接口")
    public TableDataInfo<UserListVo> greetQuery(PageQuery page, GreetQuery query){
        Page<UserListVo> res = userService.greetPageApp(page,query);
        return TableDataInfo.build(res);
    }

    @GetMapping("/home/info")
    @Operation(summary = "获取指定用户主页信息")
    public R<UserInfoVo> info(Long userId){
        UserInfoVo res = userService.info(userId);
        return R.ok(res);
    }


    @GetMapping("/userGuard/page")
    @Operation(summary = "获取指定女神守护排行")
    public TableDataInfo<GuardListPageVo> userGuardPage(PageQuery pageQuery,Long userId){
        Page<GuardListPageVo> page = guardTotalService.userGuardPage(pageQuery, userId);
        return TableDataInfo.build(page);
    }

    @GetMapping("/userGift/list")
    @Operation(summary = "获取指定女神收到的礼物列表")
    public R<List<UserGiftIndexVo>> userGiftList(Long userId){
        List<UserGiftIndexVo> res = userGiftService.selectGiftList(userId);
        return R.ok(res);
    }
}
