package com.ruoyi.xq.controller.app;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.PageModel;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.helper.LoginHelper;
import com.ruoyi.xq.dto.app.invite.UserInviteListVo;
import com.ruoyi.xq.service.UserInviteService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/invite")
@Tag(name = "邀请相关接口")
@Slf4j
public class InviteAppController {

    @Autowired
    private UserInviteService userInviteService;

    @GetMapping("/logs")
    @Operation(summary = "邀请人员记录")
    @Log(title = "邀请人员记录", businessType = BusinessType.OTHER, isPrintResponseData = false,isSaveDb = false)
    public R<PageModel<UserInviteListVo>> inviteLogs(PageQuery pageQuery){
        IPage<UserInviteListVo> res =  userInviteService.pageApp(pageQuery, LoginHelper.getUserId());
        return R.ok(PageModel.build(res));
    }

    @GetMapping("/share")
    @Operation(summary = "获取分享图片")
    @Log(title = "获取分享图片", businessType = BusinessType.OTHER, isSaveDb = true)
    public R<Map<String,String>> share(){
        String url =  userInviteService.share(LoginHelper.getUserId());
        Map<String,String> map = new HashMap<>();
        map.put("share", url);
        return R.ok(map);
    }
}
