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

import com.jeesharp.business.modules.mall.application.MallTagApplicationService;
import com.jeesharp.business.modules.mall.dto.MallTagSaveDTO;
import com.jeesharp.business.modules.mall.entity.MallTag;
import com.jeesharp.business.modules.mall.vo.MallTagInfoVO;
import com.jeesharp.business.modules.mall.vo.MallTagListVO;
import com.jeesharp.business.modules.mall.vo.MallTagQueryVO;
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;
import java.util.List;

@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/manager/business/mall/tag/v1")
@Tag(name = "商品标签管理")
@AllArgsConstructor
public class MallTagController extends BaseController {

    private final MallTagApplicationService mallTagApplicationService;

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

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

    @Operation(summary = "建品可选标签（平台已启用商品标签）")
    @PostMapping(value = "listForPublish")
    public AjaxResult<List<MallTagListVO>> listForPublish() {
        return AjaxResult.okData(mallTagApplicationService.listForPublish());
    }

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

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

    @Operation(summary = "获取启用的标签")
    @GetMapping(value = "getEnabled")
    public AjaxResult<List<MallTag>> getEnabled() {
        List<MallTag> tags = mallTagApplicationService.listEnabledTags();
        return AjaxResult.okData(tags);
    }
}
