package com.ruoyi.web.modules.home.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.web.modules.home.dto.CategoryGoodsQuery;
import com.ruoyi.web.modules.home.service.ICategoryAppService;
import com.ruoyi.web.modules.home.vo.HomeHotGoodsVO;

/**
 * C 端商品分类（全部分类树、二级 Tab、分类商品列表）
 */
@RestController
@RequestMapping("/api/category")
public class CategoryAppController extends BaseController
{
    @Autowired
    private ICategoryAppService categoryAppService;

    @Anonymous
    @GetMapping("/tree")
    public AjaxResult tree()
    {
        return success(categoryAppService.listCategoryTree());
    }

    @Anonymous
    @GetMapping("/{level1Id}/level2-tabs")
    public AjaxResult level2Tabs(@PathVariable("level1Id") Long level1Id)
    {
        return success(categoryAppService.listLevel2Tabs(level1Id));
    }

    @Anonymous
    @GetMapping("/goods")
    public TableDataInfo goods(CategoryGoodsQuery query)
    {
        startPage();
        List<HomeHotGoodsVO> list = categoryAppService.listCategoryGoods(query);
        return getDataTable(list);
    }
}
