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

import com.jeesharp.business.modules.mall.application.MallPresaleApplicationService;
import com.jeesharp.business.modules.mall.dto.MallPresaleSaveDTO;
import com.jeesharp.business.modules.mall.entity.MallPresale;
import com.jeesharp.business.modules.mall.vo.MallPresaleInfoVO;
import com.jeesharp.business.modules.mall.vo.MallPresaleListVO;
import com.jeesharp.business.modules.mall.vo.MallPresaleQueryVO;
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
 */
@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/manager/business/mall/presale/v1")
@Tag(name = "预售配置管理")
@AllArgsConstructor
public class MallPresaleController extends BaseController {

    private final MallPresaleApplicationService mallPresaleApplicationService;

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

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

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

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

    @Operation(summary = "根据SPU获取预售配置")
    @GetMapping(value = "getBySpu")
    public AjaxResult<MallPresale> getBySpu(@RequestParam("spuId") String spuId) {
        return AjaxResult.okData(mallPresaleApplicationService.getBySpuId(spuId));
    }
}
