package com.ruoyi.web.controller.info;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.info.service.domain.bo.ServiceCategorizeBo;
import com.ruoyi.info.service.domain.vo.ServiceCategorizeVo;
import com.ruoyi.info.service.service.IServiceCategorizeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 服务分类Controller
 *
 * @author ruoyi
 * @date 2025-09-20
 */
@Validated
@Api(value = "服务分类控制器", tags = {"服务分类管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/service/serviceCategorize")
public class ServiceCategorizeController extends BaseController {

    private final IServiceCategorizeService iServiceCategorizeService;

    /**
     * 分页查询服务分类列表
     */
    @ApiOperation("查询服务分类列表")
    @SaCheckPermission("service:serviceCategorize:list")
    @GetMapping("/page")
    public TableDataInfo<ServiceCategorizeVo> page(@Validated(QueryGroup.class) ServiceCategorizeBo bo, PageQuery pageQuery) {
        return iServiceCategorizeService.queryPageList(bo, pageQuery);
    }

    @ApiOperation("查询服务分类列表 用于下拉")
    @GetMapping("/list")
    public R<List<ServiceCategorizeVo>> list(@Validated(QueryGroup.class) ServiceCategorizeBo bo) {
        return R.ok(iServiceCategorizeService.queryList(bo));
    }

    /**
     * 获取服务分类详细信息
     */
    @ApiOperation("获取服务分类详细信息")
    @SaCheckPermission("service:serviceCategorize:query")
    @GetMapping("/info/{id}")
    public R<ServiceCategorizeVo> getInfo(@ApiParam("主键")
                                                  @NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return R.ok(iServiceCategorizeService.queryById(id));
    }

    /**
     * 新增服务分类
     */
    @ApiOperation("新增服务分类")
    @SaCheckPermission("service:serviceCategorize:add")
    @Log(title = "服务分类", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/add")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ServiceCategorizeBo bo) {
        return toAjax(iServiceCategorizeService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改服务分类
     */
    @ApiOperation("修改服务分类")
    @SaCheckPermission("service:serviceCategorize:edit")
    @Log(title = "服务分类", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/edit")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ServiceCategorizeBo bo) {
        return toAjax(iServiceCategorizeService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除服务分类
     */
    @ApiOperation("删除服务分类")
    @SaCheckPermission("service:serviceCategorize:remove")
    @Log(title = "服务分类", businessType = BusinessType.DELETE)
    @PostMapping("/del/{ids}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iServiceCategorizeService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

    /**
     * 修改服务分类状态
     */
    @ApiOperation("修改服务分类状态")
    @SaCheckPermission("service:serviceCategorize:status")
    @Log(title = "服务分类", businessType = BusinessType.UPDATE)
    @PostMapping("/setStatus/{id}")
    public R<Void> setStatus(@ApiParam("主键串") @NotNull(message = "主键不能为空")
                             @PathVariable Long id) {
        return toAjax(iServiceCategorizeService.setStatus(id) ? 1 : 0);
    }

}
