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

import com.jeesharp.business.modules.mall.application.MallBargainActivityApplicationService;
import com.jeesharp.business.modules.mall.dto.MallBargainActivitySaveDTO;
import com.jeesharp.business.modules.mall.entity.MallBargainActivity;
import com.jeesharp.business.modules.mall.vo.MallBargainActivityInfoVO;
import com.jeesharp.business.modules.mall.vo.MallBargainActivityListVO;
import com.jeesharp.business.modules.mall.vo.MallBargainActivityQueryVO;
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;

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

    private final MallBargainActivityApplicationService mallBargainActivityApplicationService;

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

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

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

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

    @Operation(summary = "获取进行中的活动")
    @GetMapping(value = "active")
    public AjaxResult<List<MallBargainActivity>> getActiveActivities() {
        List<MallBargainActivity> activities = mallBargainActivityApplicationService.getActiveActivities();
        return AjaxResult.okData(activities);
    }

    @Operation(summary = "根据SKU获取活动")
    @GetMapping(value = "getBySku")
    public AjaxResult<MallBargainActivity> getBySku(@RequestParam("skuId") String skuId) {
        MallBargainActivity activity = mallBargainActivityApplicationService.getBySkuId(skuId);
        return AjaxResult.okData(activity);
    }
}
