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

import com.jeesharp.business.modules.mall.application.MallSpecValueApplicationService;
import com.jeesharp.business.modules.mall.dto.MallSpecValueCreateForPublishDTO;
import com.jeesharp.business.modules.mall.dto.MallSpecValueSaveDTO;
import com.jeesharp.business.modules.mall.entity.MallSpecValue;
import com.jeesharp.business.modules.mall.vo.MallSpecValueInfoVO;
import com.jeesharp.business.modules.mall.vo.MallSpecValueListVO;
import com.jeesharp.business.modules.mall.vo.MallSpecValueQueryVO;
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 jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 规格值管理端 REST 接口。
 *
 * @author jeesharp
 * @since 2026-05-07
 */
@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/manager/business/mall/specValue/v1")
@Tag(name = "商品规格值管理")
@AllArgsConstructor
public class MallSpecValueController extends BaseController {

    private final MallSpecValueApplicationService mallSpecValueApplicationService;

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

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

    @Operation(summary = "建品可选规格值（当前商户租户）")
    @PostMapping(value = "listForPublish")
    public AjaxResult<java.util.List<MallSpecValueListVO>> listForPublish(@RequestBody MallSpecValueQueryVO query) {
        return AjaxResult.okData(mallSpecValueApplicationService.listForPublish(query));
    }

    @Operation(summary = "发品页新增规格值")
    @PostMapping(value = "createForPublish")
    public AjaxResult<MallSpecValueListVO> createForPublish(@RequestBody @Valid MallSpecValueCreateForPublishDTO dto) {
        return AjaxResult.okData(mallSpecValueApplicationService.createForPublish(dto));
    }

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

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