package org.lym.pom.controller;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.lym.pom.dto.posts.AttitudeIndexDTO;
import org.lym.pom.repository.mongo.Attitude;
import org.lym.pom.service.AttitudeService;
import org.shoulder.core.dto.response.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/attitude")
public class AttitudeController extends BaseController {

    @Autowired
    private AttitudeService attitudeService;

    @PostMapping("add")
    public BaseResult<Boolean> addAttitude(@Valid @NotNull AttitudeIndexDTO attitudeIndexDTO) {

        Attitude attitude = converionService.convert(attitudeIndexDTO, Attitude.class);

        boolean success = attitudeService.addAttitude(attitude);
        return BaseResult.success(success);
    }


    // 移除赞或踩操作
    @PostMapping("cancel")
    public BaseResult<Void> cancel(@Valid @NotNull AttitudeIndexDTO attitudeIndexDTO) {
        Attitude attitude = converionService.convert(attitudeIndexDTO, Attitude.class);

        attitudeService.removeAttitude(attitude);
        return BaseResult.success();
    }

    // 查询单条 Attitude
//    @GetMapping("/{relatedType}/{relatedId}/detail")
//    public BaseResult<Attitude> queryAttitudeDetail(@PathVariable("relatedId") String relatedId,
//                                                    @PathVariable("relatedType") String relatedType,
//                                                    @RequestParam("userId") String userId) {
//        Attitude attitude = attitudeService.queryAttitudeDetail(relatedId, relatedType, userId);
//        return BaseResult.success(attitude);
//    }

    // 统计某个对象的赞和踩数量
//    @GetMapping("/{relatedType}/{relatedId}/count")
//    public BaseResult<Map<String, Integer>> countAttitudeNumber(@PathVariable("relatedId") String relatedId,
//                                                                @PathVariable("relatedType") String relatedType) {
//        Map<String, Integer> result = attitudeService.countAttitudeNumber(relatedId, relatedType);
//        return BaseResult.success(result);
//    }
}
