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

import cn.hutool.core.util.StrUtil;

import com.jeesharp.business.modules.setting.application.SiteIconApplicationService;
import com.jeesharp.business.modules.setting.dto.SiteIconSaveDTO;
import com.jeesharp.business.modules.setting.entity.CmsSiteIcon;
import com.jeesharp.business.modules.setting.vo.SiteIconListVO;
import com.jeesharp.business.modules.setting.vo.SiteIconQueryVO;
import com.jeesharp.business.modules.setting.vo.SiteIconVO;
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/siteIcon/v1")
@Tag(name = "站点设置-站点图标")
@AllArgsConstructor
public class SiteIconController extends BaseController {

    private final SiteIconApplicationService siteIconApplicationService;

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

    @Operation(summary = "分页列表")
    @PreAuthorize("@ss.hasPermission('setting:siteIcon:list')")
    @PostMapping("list")
    public AjaxResult<PageRespVO<SiteIconListVO>> list(@RequestBody SiteIconQueryVO query) {
        return AjaxResult.okData(siteIconApplicationService.findPage(new Page<CmsSiteIcon>(query), query));
    }

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

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