package cn.iocoder.yudao.module.system.controller.admin.nursing;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.NursingCategoryDO;
import cn.iocoder.yudao.module.system.service.nursing.NursingCategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 护理分类")
@RestController
@RequestMapping("/nursingCategory")
public class NursingCategoryController {

    @Resource
    private NursingCategoryService nursingCategoryService;


    @PostMapping("/add")
    @Operation(summary = "新增护理分类")
    @TenantIgnore
    public CommonResult<Boolean> add(@RequestBody NursingCategoryDO category) {
        nursingCategoryService.add(category);
        return success(true);
    }

    @PostMapping("/edit")
    @Operation(summary = "编辑护理分类")
    public CommonResult<Boolean> edit(@RequestBody NursingCategoryDO category) {
        nursingCategoryService.edit(category);
        return success(true);
    }

    @GetMapping("/getDetailById")
    @Operation(summary = "获取护理分类详情")
    public CommonResult<NursingCategoryDO> getDetailById(@RequestParam Long id) {
        return success(nursingCategoryService.getDetailById(id));
    }


    @DeleteMapping("/delete")
    @Operation(summary = "删除护理分类")
    public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
        nursingCategoryService.delete(id);
        return success(true);
    }


    @GetMapping("/getTree")
    @Operation(summary = "获取护理分类树")
    @TenantIgnore
    public CommonResult<List<NursingCategoryDO>> getTree(@RequestParam(value = "tenantIds", required = false) Long[] tenantIds,
                                                         @RequestParam(value = "orgType", required = false) Integer orgType) {
        tenantIds = Objects.isNull(tenantIds) ? (Long[]) Arrays.asList(TenantContextHolder.getTenantId()).toArray() : tenantIds;
        return success(nursingCategoryService.getTree(tenantIds, orgType));
    }
}
