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

import cn.hutool.core.util.StrUtil;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.jeesharp.business.modules.setting.application.AboutUsApplicationService;
import com.jeesharp.business.modules.setting.dto.AboutUsSaveDTO;
import com.jeesharp.business.modules.setting.vo.AboutUsListVO;
import com.jeesharp.business.modules.setting.vo.AboutUsQueryVO;
import com.jeesharp.business.modules.setting.vo.AboutUsInfoVO;
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.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
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.*;

/**
 * 关于我们管理 Controller（后台管理）
 *
 * @author jeesharp
 * @version 2026-02-05
 */
@RestController
@RequestMapping(value = "${jeesharp.web.adminPath}/setting/aboutUs/v1")
@Tag(name = "关于我们管理", description = "关于我们管理相关接口，包括关于我们的增删改查等功能")
@AllArgsConstructor
public class AboutUsController extends BaseController {

    private final AboutUsApplicationService aboutUsApplicationService;

    // ==================== 基础 CRUD ====================

    /**
     * 获取关于我们详情
     */
    @ApiOperationSupport(order = 1)
    @Operation(summary = "1、获取关于我们详情", description = "根据ID获取关于我们的详细信息")
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "操作成功"),
            @ApiResponse(responseCode = "403", description = "无权限访问")
    })
    @PreAuthorize("@ss.hasPermission('setting:aboutUs:info')")
    @GetMapping(value = "info")
    public AjaxResult<AboutUsInfoVO> info(
            @Parameter(description = "ID", required = true)
            @RequestParam("id") String id) {
        return AjaxResult.okData(aboutUsApplicationService.getAboutUs(id));
    }

    /**
     * 获取关于我们列表（分页）
     */
    @ApiOperationSupport(order = 2)
    @Operation(summary = "2、获取关于我们列表", description = "分页查询关于我们列表，支持多条件筛选")
    @PreAuthorize("@ss.hasPermission('setting:aboutUs:list')")
    @PostMapping(value = "list")
    public AjaxResult<PageRespVO<AboutUsListVO>> list(@RequestBody AboutUsQueryVO query) {
        PageRespVO<AboutUsListVO> page = aboutUsApplicationService.findPage(new Page<>(query), query);
        return AjaxResult.okData(page);
    }

    /**
     * 保存关于我们
     */
    @ApiOperationSupport(order = 3)
    @Operation(summary = "3、保存关于我们", description = "新增或更新关于我们信息，ID为空时新增，否则更新")
    @PreAuthorize("@ss.hasPermission('setting:aboutUs:save')")
    @PostMapping(value = "save")
    public AjaxResult<Void> save(@RequestBody @Valid AboutUsSaveDTO dto) {
        aboutUsApplicationService.save(dto);
        return AjaxResult.ok("保存成功");
    }

    /**
     * 删除关于我们
     */
    @ApiOperationSupport(order = 4)
    @Operation(summary = "4、删除关于我们", description = "批量删除关于我们，多个ID用逗号分隔")
    @PreAuthorize("@ss.hasPermission('setting:aboutUs:delete')")
    @GetMapping(value = "delete")
    public AjaxResult<Void> delete(
            @Parameter(description = "ID，多个用逗号分隔", required = true)
            @RequestParam("ids") String ids) {
        aboutUsApplicationService.delete(ids);
        return AjaxResult.ok("删除成功");
    }

    // ==================== 状态管理 ====================

    /**
     * 禁用关于我们
     */
    @ApiOperationSupport(order = 5)
    @Operation(summary = "5、禁用关于我们", description = "禁用指定的关于我们")
    @PreAuthorize("@ss.hasPermission('setting:aboutUs:disable')")
    @GetMapping(value = "disable")
    public AjaxResult<Void> disable(
            @Parameter(description = "ID", required = true)
            @RequestParam("id") String id) {
        aboutUsApplicationService.disable(id);
        return AjaxResult.ok("禁用成功");
    }

    /**
     * 启用关于我们
     */
    @ApiOperationSupport(order = 6)
    @Operation(summary = "6、启用关于我们", description = "启用指定的关于我们")
    @PreAuthorize("@ss.hasPermission('setting:aboutUs:enable')")
    @GetMapping(value = "enable")
    public AjaxResult<Void> enable(
            @Parameter(description = "ID", required = true)
            @RequestParam("id") String id) {
        aboutUsApplicationService.enable(id);
        return AjaxResult.ok("启用成功");
    }
}
