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

import cn.hutool.core.util.StrUtil;

import com.jeesharp.business.modules.setting.application.HomeGridIntroApplicationService;
import com.jeesharp.business.modules.setting.dto.HomeGridIntroSaveDTO;
import com.jeesharp.business.modules.setting.entity.CmsHomeGridIntro;
import com.jeesharp.business.modules.setting.vo.HomeGridIntroListVO;
import com.jeesharp.business.modules.setting.vo.HomeGridIntroQueryVO;
import com.jeesharp.business.modules.setting.vo.HomeGridIntroVO;
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.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 首页宫格介绍文章管理（后台管理端）。
 *
 * @author jeesharp
 * @since 2026-05-15
 */
@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/setting/homeGridIntro/v1")
@Tag(name = "站点设置-宫格介绍")
@AllArgsConstructor
public class HomeGridIntroController extends BaseController {

    private final HomeGridIntroApplicationService homeGridIntroApplicationService;

    @Operation(summary = "获取详情")
    @PreAuthorize("@ss.hasPermission('setting:homeGridIntro:info')")
    @GetMapping("info")
    public AjaxResult<HomeGridIntroVO> info(@RequestParam("id") String id) {
        return AjaxResult.okData(homeGridIntroApplicationService.get(id));
    }

    @Operation(summary = "分页列表")
    @PreAuthorize("@ss.hasPermission('setting:homeGridIntro:list')")
    @PostMapping("list")
    public AjaxResult<PageRespVO<HomeGridIntroListVO>> list(@RequestBody HomeGridIntroQueryVO query) {
        return AjaxResult.okData(homeGridIntroApplicationService.findPage(new Page<CmsHomeGridIntro>(query), query));
    }

    @Operation(summary = "保存")
    @PreAuthorize("@ss.hasPermission('setting:homeGridIntro:save')")
    @PostMapping("save")
    public AjaxResult<Void> save(@RequestBody @Valid HomeGridIntroSaveDTO dto) {
        homeGridIntroApplicationService.save(dto);
        return AjaxResult.ok("保存成功");
    }

    @Operation(summary = "删除")
    @PreAuthorize("@ss.hasPermission('setting:homeGridIntro:delete')")
    @GetMapping("delete")
    public AjaxResult<Void> delete(@RequestParam("ids") String ids) {
        homeGridIntroApplicationService.delete(ids);
        return AjaxResult.ok("删除成功");
    }
}
