package cn.qinys.platform.mobile.mapper;

import cn.qinys.platform.entity.wishing.WishingTree;
import cn.qinys.platform.mobile.resp.TreeDetailResp;
import cn.qinys.platform.mobile.resp.TreeListResp;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author lie tan
 * @description
 * @date 2026-05-23 12:41
 **/
@Mapper
public interface WishingTreeMapper extends BaseMapper<WishingTree> {

    /**
     * 首页许愿数列表
     *
     * @return
     */
    @Select("SELECT t.*, e.total_count as totalWishes FROM wishing_tree t " +
            "LEFT JOIN wishing_tree_extension e ON t.id = e.tree_id " +
            "WHERE t.is_active = 1 AND t.is_deleted = 0")
    List<TreeListResp> selectActiveTrees();

    /**
     * 许愿数详情
     *
     * @param id
     * @return
     */
    @Select("SELECT t.*, e.total_count as totalWishes FROM wishing_tree t " +
            "LEFT JOIN wishing_tree_extension e ON t.id = e.tree_id " +
            "WHERE t.id = #{id} LIMIT 1")
    TreeDetailResp selectDetailById(@Param("id") Integer id);

}
