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

import com.jeesharp.business.modules.mall.application.MallPickupPointApplicationService;
import com.jeesharp.business.modules.mall.dto.MallPickupPointSaveDTO;
import com.jeesharp.business.modules.mall.entity.MallPickupPoint;
import com.jeesharp.business.modules.mall.vo.MallPickupPointInfoVO;
import com.jeesharp.business.modules.mall.vo.MallPickupPointListVO;
import com.jeesharp.business.modules.mall.vo.MallPickupPointQueryVO;
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/pickupPoint/v1")
@Tag(name = "到店自提点管理")
@AllArgsConstructor
public class MallPickupPointController extends BaseController {

    private final MallPickupPointApplicationService mallPickupPointApplicationService;

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

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

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

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

    @Operation(summary = "获取启用的自提点")
    @GetMapping(value = "getEnabled")
    public AjaxResult<List<MallPickupPoint>> getEnabled() {
        List<MallPickupPoint> points = mallPickupPointApplicationService.listEnabledPoints();
        return AjaxResult.okData(points);
    }
}
