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

import com.jeesharp.business.modules.mall.application.MallBrowseFootprintApplicationService;
import com.jeesharp.business.modules.mall.dto.MallBrowseFootprintSaveDTO;
import com.jeesharp.business.modules.mall.entity.MallBrowseFootprint;
import com.jeesharp.business.modules.mall.vo.MallBrowseFootprintInfoVO;
import com.jeesharp.business.modules.mall.vo.MallBrowseFootprintListVO;
import com.jeesharp.business.modules.mall.vo.MallBrowseFootprintQueryVO;
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;

/**
 * 浏览足迹管理端接口，提供运营侧分页查询、详情、保存与删除。
 *
 * @author jeesharp
 * @since 2026-05-07
 */
@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/manager/business/mall/browseFootprint/v1")
@Tag(name = "浏览足迹管理")
@AllArgsConstructor
public class MallBrowseFootprintController extends BaseController {

    private final MallBrowseFootprintApplicationService mallBrowseFootprintApplicationService;

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

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

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

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