package cn.qinys.platform.mobile.controller;

import cn.qinys.platform.base.response.Result;
import cn.qinys.platform.mobile.req.WishingTreeListReq;
import cn.qinys.platform.mobile.resp.WishingTreeListResp;
import cn.qinys.platform.mobile.service.WishTreeService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lie tan
 * @description 许愿树移动端接口
 * @date 2026-05-17 22:25
 **/
@RestController
@RequestMapping("/dgapi/mobile/wishingtree")
public class WishingTreeController {

    @Resource
    private WishTreeService wishTreeService;

    /**
     * 查询附近许愿树列表
     */
    @PostMapping("/list")
    public Result<List<WishingTreeListResp>> list(@RequestBody @Valid WishingTreeListReq req) {
        List<WishingTreeListResp> list = wishTreeService.listNearbyTrees(req);
        return new Result<>(list);
    }

    /**
     * 许愿树详情
     */
    @GetMapping("/{id}")
    public Result<WishingTreeListResp> detail(@PathVariable Long id) {
        WishingTreeListResp resp = wishTreeService.getTreeDetail(id);
        return resp != null ? new Result<>(resp) : new Result<>(404, "许愿树不存在");
    }
}
