package com.ruoyi.cai.controller.app;

import com.ruoyi.cai.domain.User;
import com.ruoyi.cai.domain.UserGreet;
import com.ruoyi.cai.dto.app.query.IdRes;
import com.ruoyi.cai.dto.app.query.user.UserGreetAddReq;
import com.ruoyi.cai.dto.app.vo.user.UserGreetVo;
import com.ruoyi.cai.service.UserGreetService;
import com.ruoyi.cai.service.UserService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.helper.LoginHelper;
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.*;

import java.util.List;

@RestController
@RequestMapping("/api/user/greet")
@Tag(name = "群打招呼相关接口")
public class UserGreetAppController {

    @Autowired
    private UserGreetService userGreetService;
    @Autowired
    private UserService userService;

    @GetMapping("/list")
    @Operation(summary = "获取当前用户打招呼列表")
    public R<List<UserGreetVo>> list(){
        Long userId = LoginHelper.getUserId();
        User user = userService.getById(userId);
        if(user == null || user.getIsAnchor() == 0){
            return R.fail(600, "您不是女神，无法群打招呼，快去申请吧!");
        }
        List<UserGreet> userGreet = userGreetService.listByUserId(userId);
        return R.ok(BeanConvertUtil.convertListTo(userGreet,UserGreetVo::new));
    }

    @GetMapping("/add")
    @Operation(summary = "新增群打招呼")
    public R<Void> add(@RequestBody UserGreetAddReq req){
        userGreetService.addUserGreet(req);
        return R.ok();
    }


    @PostMapping("/delete")
    @Operation(summary = "删除群打招呼")
    public R<Void> add(@RequestBody IdRes req){
        userGreetService.removeById(req.getId());
        return R.ok();
    }

    @PostMapping("/send")
    @Operation(summary = "群打招呼")
    public R<Void> send(@RequestBody IdRes req){
        userGreetService.batchSend(req.getId(),LoginHelper.getUserId());
        return R.ok();
    }

}
