package org.dromara.controller.butler;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.domain.butler.bo.ButlerSettingsBo;
import org.dromara.domain.butler.vo.ButlerSettingsVo;
import org.dromara.service.IButlerSettingsService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 物业管家设置
 *
 * @author boman
 * @date 2025-04-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wuYe/settings")
public class ButlerSettingsController extends BaseController {

    private final IButlerSettingsService butlerSettingsService;

    /**
     * 查询物业管家设置列表
     */
    @SaCheckPermission("wuYe:settings:list")
    @GetMapping("/list")
    public TableDataInfo<ButlerSettingsVo> list(ButlerSettingsBo bo, PageQuery pageQuery) {
        return butlerSettingsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出物业管家设置列表
     */
    @SaCheckPermission("wuYe:settings:export")
    @Log(title = "物业管家设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ButlerSettingsBo bo, HttpServletResponse response) {
        List<ButlerSettingsVo> list = butlerSettingsService.queryList(bo);
        ExcelUtil.exportExcel(list, "物业管家设置", ButlerSettingsVo.class, response);
    }

    /**
     * 获取物业管家设置详细信息
     *
     * @param settingsId 主键
     */
    @SaCheckPermission("wuYe:settings:query")
    @GetMapping("/{settingsId}")
    public R<ButlerSettingsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long settingsId) {
        return R.ok(butlerSettingsService.queryById(settingsId));
    }

    /**
     * 新增物业管家设置
     */
    @SaCheckPermission("wuYe:settings:add")
    @Log(title = "物业管家设置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ButlerSettingsBo bo) {
        return toAjax(butlerSettingsService.insertByBo(bo));
    }

    /**
     * 修改物业管家设置
     */
    @SaCheckPermission("wuYe:settings:edit")
    @Log(title = "物业管家设置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ButlerSettingsBo bo) {
        return toAjax(butlerSettingsService.updateByBo(bo));
    }

    /**
     * 删除物业管家设置
     *
     * @param settingsIds 主键串
     */
    @SaCheckPermission("wuYe:settings:remove")
    @Log(title = "物业管家设置", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{settingsIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] settingsIds) {
        return toAjax(butlerSettingsService.deleteWithValidByIds(List.of(settingsIds), true));
    }
}
