package com.ruoyi.cai.controller.app;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.cai.dto.app.query.StarOrVisitorReq;
import com.ruoyi.cai.dto.app.query.StarQuery;
import com.ruoyi.cai.dto.app.vo.user.UserStarOrVisitorList;
import com.ruoyi.cai.service.UserFollowService;
import com.ruoyi.common.annotation.Log;
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.enums.BusinessType;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/user/star")
@Tag(name = "关注相关接口")
public class UserStartAppController {

    @Autowired
    private UserFollowService userFollowService;

    @PostMapping("/star")
    @Operation(summary = "关注用户")
    @Log(title = "关注用户", businessType = BusinessType.OTHER, isSaveDb = true)
    public R<Void> star(@Validated @RequestBody StarOrVisitorReq starOrVisitorReq){
        userFollowService.star(starOrVisitorReq);
        return R.ok();
    }

    @PostMapping("/unstar")
    @Operation(summary = "取消关注用户")
    @Log(title = "取消关注用户", businessType = BusinessType.OTHER, isSaveDb = true)
    public R<Void> unStar(@Validated @RequestBody StarOrVisitorReq starOrVisitorReq){
        userFollowService.unStar(starOrVisitorReq);
        return R.ok();
    }

    @GetMapping("/page")
    @Operation(summary = "关注、粉丝列表查询")
    @Log(title = "粉丝列表查询", businessType = BusinessType.OTHER, isSaveDb = false)
    public R<List<UserStarOrVisitorList>> page(StarQuery query, PageQuery pageQuery){
        Page<UserStarOrVisitorList> res = userFollowService.pageApp(pageQuery,query);
        return R.ok(res.getRecords());
    }

}
