package org.dromara.controller.houseInfo;

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.houseInfo.bo.PropertySettingsBo;
import org.dromara.domain.houseInfo.vo.PropertySettingsVo;
import org.dromara.service.IPropertySettingsService;
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/fee/settings")
public class PropertySettingsController extends BaseController {

    private final IPropertySettingsService propertySettingsService;

    /**
     * 查询物业费设置列表
     */
    @SaCheckPermission("wuYe:fee:settings:list")
    @GetMapping("/list")
    public TableDataInfo<PropertySettingsVo> list(PropertySettingsBo bo, PageQuery pageQuery) {
        return propertySettingsService.queryPageList(bo, pageQuery);
    }

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

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

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

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

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