package com.luojia_channel.modules.interact.controller;

import com.luojia_channel.common.domain.Result;
import com.luojia_channel.common.domain.UserDTO;
import com.luojia_channel.common.domain.page.PageResponse;
import com.luojia_channel.common.domain.page.ScrollPageResponse;
import com.luojia_channel.modules.interact.service.FollowService;
import com.luojia_channel.modules.post.dto.req.PostPageQueryDTO;
import com.luojia_channel.modules.post.dto.resp.PostBasicInfoDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/follow")
@RequiredArgsConstructor
@Tag(name = "关注模块", description = "用户之间互相关注模块")
public class FollowController {

    private final FollowService followService;
    @PutMapping("/{id}/{isFollow}")
    @Operation(
            summary = "关注用户",
            description = "关注用户，传入用户id和是否关注的状态",
            tags = {"关注模块"}
    )
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "操作成功"),
            @ApiResponse(responseCode = "500", description = "操作失败，请稍后重试")
    })
    public Result<Void> follow(@PathVariable("id") Long followUserId, @PathVariable("isFollow") Boolean isFollow){
        followService.follow(followUserId, isFollow);
        return Result.success();
    }
    @GetMapping("/or/not/{id}")
    @Operation(
            summary = "是否关注用户",
            description = "传入用户id，返回是否关注该用户",
            tags = {"关注模块"}
    )
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "已关注"),
            @ApiResponse(responseCode = "500", description = "未关注")
    })
    public Result<Boolean> isFollow(@PathVariable("id") Long followUserId){
        return Result.success(followService.isFollow(followUserId));
    }
    @GetMapping("/common/{id}")
    @Operation(
            summary = "共同关注",
            description = "传入用户id，返回该与该用户的共同关注",
            tags = {"关注模块"}
    )
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "获取成功"),
            @ApiResponse(responseCode = "500", description = "获取失败，请稍后重试")
    })
    public Result<List<UserDTO>> followCommons(@PathVariable("id") Long id){
        return Result.success(followService.followCommons(id));
    }

    @GetMapping("/post")
    @Operation(
            summary = "关注收件箱",
            description = "传入分页参数，查询关注的人的发帖推送",
            tags = {"关注模块"}
    )
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "获取成功"),
            @ApiResponse(responseCode = "500", description = "获取失败，请稍后重试")
    })
    public Result<ScrollPageResponse<PostBasicInfoDTO>> queryPostFollow(@RequestBody PostPageQueryDTO postPageQueryDTO){
        return Result.success(followService.queryPostFollow(postPageQueryDTO));
    }
}
