package com.jeesharp.business.modules.mall.controller;

import com.jeesharp.business.modules.mall.application.MallCategoryApplicationService;
import com.jeesharp.business.modules.mall.dto.MallCategorySaveDTO;
import com.jeesharp.business.modules.mall.vo.MallCategoryInfoVO;
import com.jeesharp.business.modules.mall.vo.MallCategoryListVO;
import com.jeesharp.business.modules.mall.vo.MallCategoryQueryVO;
import com.jeesharp.framework.pojo.AjaxResult;
import com.jeesharp.framework.pojo.Page;
import com.jeesharp.framework.pojo.query.PageRespVO;
import com.jeesharp.framework.web.controller.BaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

/**
 * 商品类目（商品分类）管理 Controller，路径与表名沿用 {@code category}。
 */
@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/manager/business/mall/category/v1")
@Tag(name = "商品类目管理")
@AllArgsConstructor
public class MallCategoryController extends BaseController {

    private final MallCategoryApplicationService mallCategoryApplicationService;

    @Operation(summary = "获取详情")
    @GetMapping(value = "info")
    public AjaxResult<MallCategoryInfoVO> info(@RequestParam("id") String id) {
        MallCategoryInfoVO vo = mallCategoryApplicationService.get(id);
        return AjaxResult.okData(vo);
    }

    @Operation(summary = "获取列表（分页）")
    @PostMapping(value = "list")
    public AjaxResult<PageRespVO<MallCategoryListVO>> list(@RequestBody MallCategoryQueryVO query) {
        PageRespVO<MallCategoryListVO> page = mallCategoryApplicationService.findPage(new Page<>(query), query);
        return AjaxResult.okData(page);
    }

    @Operation(summary = "建品可选类目（平台已启用）")
    @PostMapping(value = "listForPublish")
    public AjaxResult<java.util.List<MallCategoryListVO>> listForPublish() {
        return AjaxResult.okData(mallCategoryApplicationService.listForPublish());
    }

    @Operation(summary = "保存")
    @PostMapping(value = "save")
    public AjaxResult<Void> save(@RequestBody @Valid MallCategorySaveDTO dto) {
        mallCategoryApplicationService.save(dto);
        return AjaxResult.ok("保存成功");
    }

    @Operation(summary = "删除")
    @GetMapping(value = "delete")
    public AjaxResult<Void> delete(@RequestParam("ids") String ids) {
        mallCategoryApplicationService.delete(ids);
        return AjaxResult.ok("删除成功");
    }
}
