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

import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.module.system.controller.admin.sys.vo.ServiceItemPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.sys.vo.ServiceItemRespVO;
import cn.iocoder.yudao.module.system.controller.admin.sys.vo.ServiceItemSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.ServiceItemDO;
import cn.iocoder.yudao.module.system.dal.dataobject.biz.ServiceItemLevelDO;
import cn.iocoder.yudao.module.system.service.sys.ServiceItemService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;


/**
 * @Author: jinyd
 * @CreateTime: 2025/4/1  11:53
 * @Description:
 * @Version: 4.0
 */

@Tag(name = "管理后台 - 服务项目")
@RestController
@RequestMapping("/sys/service-item")
@Validated
public class ServiceItemController {

    @Resource
    private ServiceItemService serviceItemService;

    @PostMapping("/create")
    @Operation(summary = "创建服务项目")
    @TenantIgnore
    public CommonResult<Long> createServiceItem(@Valid @RequestBody ServiceItemSaveReqVO createReqVO) {
        createReqVO.setTenantId(createReqVO.getTenantId()  == null ? TenantContextHolder.getTenantId() : createReqVO.getTenantId());
        return success(serviceItemService.createServiceItem(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新服务项目")
    @TenantIgnore
    public CommonResult<Boolean> updateServiceItem(@Valid @RequestBody ServiceItemSaveReqVO updateReqVO) {
        updateReqVO.setTenantId(updateReqVO.getTenantId()  == null ? TenantContextHolder.getTenantId() : updateReqVO.getTenantId());
        serviceItemService.updateServiceItem(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除服务项目")
    @Parameter(name = "id", description = "编号", required = true)
    @TenantIgnore
    public CommonResult<Boolean> deleteServiceItem(@RequestParam("id") Long id) {
        serviceItemService.deleteServiceItem(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得服务项目")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @TenantIgnore
    public CommonResult<ServiceItemRespVO> getServiceItem(@RequestParam("id") Long id) {
        ServiceItemDO serviceItem = serviceItemService.getServiceItem(id);
        return success(BeanUtils.toBean(serviceItem, ServiceItemRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得服务项目分页")
    @TenantIgnore
    public CommonResult<PageResult<ServiceItemRespVO>> getServiceItemPage(@Valid ServiceItemPageReqVO pageReqVO) {
        pageReqVO.setTenantIds(Objects.isNull(pageReqVO.getTenantIds()) ? new Long[]{TenantContextHolder.getTenantId()} : pageReqVO.getTenantIds());
        PageResult<ServiceItemDO> pageResult = serviceItemService.getServiceItemPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ServiceItemRespVO.class));
    }



}
