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

import com.jeesharp.business.modules.mall.application.MallBargainHelpApplicationService;
import com.jeesharp.business.modules.mall.dto.MallBargainHelpSaveDTO;
import com.jeesharp.business.modules.mall.vo.MallBargainHelpInfoVO;
import com.jeesharp.business.modules.mall.vo.MallBargainHelpListVO;
import com.jeesharp.business.modules.mall.vo.MallBargainHelpQueryVO;
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.math.BigDecimal;
import java.util.List;

/**
 * 砍价助力管理 Controller
 */
@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/manager/business/mall/bargainHelp/v1")
@Tag(name = "砍价助力管理")
@AllArgsConstructor
public class MallBargainHelpController extends BaseController {

    private final MallBargainHelpApplicationService mallBargainHelpApplicationService;

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

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

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

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

    @Operation(summary = "获取砍价助力列表")
    @GetMapping(value = "getByRecord")
    public AjaxResult<List<MallBargainHelpInfoVO>> getByRecord(@RequestParam("recordId") String recordId) {
        List<MallBargainHelpInfoVO> helps = mallBargainHelpApplicationService.getBargainHelps(recordId);
        return AjaxResult.okData(helps);
    }
}
