package cn.hanghui.outapi.platform.tenant.controller;

import cn.hanghui.outapi.platform.common.config.log.Log;
import cn.hanghui.outapi.platform.common.entity.rest.RestResponse;
import cn.hanghui.outapi.platform.common.entity.rest.RestResult;
import cn.hanghui.outapi.platform.tenant.entity.config.maintenance.application.device.ApplicationTypeDto;
import cn.hanghui.outapi.platform.tenant.entity.config.maintenance.application.device.ApplicationTypeSearch;
import cn.hanghui.outapi.platform.tenant.entity.config.maintenance.application.device.ApplicationTypeVo;
import cn.hanghui.outapi.platform.tenant.entity.config.maintenance.device.DeviceModelDto;
import cn.hanghui.outapi.platform.tenant.entity.config.maintenance.device.DeviceModelSearch;
import cn.hanghui.outapi.platform.tenant.entity.config.maintenance.device.DeviceModelVo;
import cn.hanghui.outapi.platform.tenant.entity.config.maintenance.purchaser.PurchaserDto;
import cn.hanghui.outapi.platform.tenant.entity.config.maintenance.purchaser.PurchaserSearch;
import cn.hanghui.outapi.platform.tenant.entity.config.maintenance.purchaser.PurchaserVo;
import cn.hanghui.outapi.platform.tenant.entity.enums.BusinessTypeEnum;
import cn.hanghui.outapi.platform.tenant.entity.enums.LogTagEnum;
import cn.hanghui.outapi.platform.tenant.service.ApplicationTypeService;
import cn.hanghui.outapi.platform.tenant.service.DeviceModelService;
import cn.hanghui.outapi.platform.tenant.service.PurchaserService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @description:
 * @ClassName ConfigMaintenanceController
 * @Author WXG
 * @Date 2023/12/27 11:43
 */
@Slf4j
@Api(tags = "购买方-设备类型-应用类型")
@RestController
@RequestMapping(value = "/api/v1/config")
@Validated
public class ConfigMaintenanceController {

    @Resource
    private  PurchaserService purchaserService;
    @Resource
    private DeviceModelService deviceModelService;
    @Resource
    private ApplicationTypeService applicationTypeService;
    @ApiOperation("购买方-新增/编辑")
    @PostMapping("purchaser/edit")
    @ApiOperationSupport(order = 10)
    @Log(tag = LogTagEnum.PURCHASER,title = "添加/编辑购买方公司",businessTypeEnum = BusinessTypeEnum.INSERT_UPDATE)
    public RestResult<Boolean> edit(@RequestBody @Valid PurchaserDto dto) {
        return RestResponse.ok(purchaserService.edit(dto));
    }
    @ApiOperation("购买方列表")
    @GetMapping("purchaser/list")
    @ApiOperationSupport(order = 20)
    public RestResult<List<PurchaserVo>> purchaserList() {
        return RestResponse.ok(purchaserService.purchaserList());
    }
    @ApiOperation("购买方列表(分页)")
    @PostMapping("purchaser/page")
    @ApiOperationSupport(order = 30)
    public RestResult<IPage<PurchaserVo>> purchaserPage(@RequestBody PurchaserSearch dto) {
        return RestResponse.ok(purchaserService.purchaserPage(dto));
    }
    @ApiOperation("购买方-删除")
    @DeleteMapping("purchaser/{purchaserId}")
    @ApiOperationSupport(order = 40)
    @Log(tag = LogTagEnum.PURCHASER,title = "删除购买方公司",businessTypeEnum = BusinessTypeEnum.DELETE)
    public RestResult<Boolean> purchaserDelete(@PathVariable(value = "purchaserId") Long purchaserId) {
        return RestResponse.ok(purchaserService.purchaserDelete(purchaserId));
    }


    @ApiOperation("设备型号-新增/编辑")
    @PostMapping("deviceModel/edit")
    @ApiOperationSupport(order = 110)
    @Log(tag = LogTagEnum.DEVICEMODEL,title = "添加/编辑设备型号",businessTypeEnum = BusinessTypeEnum.INSERT_UPDATE)
    public RestResult<Boolean> edit(@RequestBody @Valid DeviceModelDto dto) {
        return RestResponse.ok(deviceModelService.edit(dto));
    }
    @ApiOperation("设备型号列表")
    @GetMapping("deviceModel/list")
    @ApiOperationSupport(order = 120)
    public RestResult<List<DeviceModelVo>> deviceModelList() {
        return RestResponse.ok(deviceModelService.deviceModelList());
    }
    @ApiOperation("设备型号列表(分页)")
    @PostMapping("deviceModel/page")
    @ApiOperationSupport(order = 130)
    public RestResult<IPage<DeviceModelVo>> deviceModelPage(@RequestBody DeviceModelSearch dto) {
        return RestResponse.ok(deviceModelService.deviceModelPage(dto));
    }
    @ApiOperation("设备型号-删除")
    @DeleteMapping("deviceModel/{deviceModelId}")
    @ApiOperationSupport(order = 140)
    @Log(tag = LogTagEnum.DEVICEMODEL,title = "删除设备型号",businessTypeEnum = BusinessTypeEnum.DELETE)
    public RestResult<Boolean> deviceModelDelete(@PathVariable(value = "deviceModelId") Long deviceModelId) {
        return RestResponse.ok(deviceModelService.deviceModelDelete(deviceModelId));
    }


    @ApiOperation("应用类型-新增/编辑")
    @PostMapping("applicationType/edit")
    @ApiOperationSupport(order = 110)
    @Log(tag = LogTagEnum.APPLICATIONTYPE,title = "添加/编辑应用类型",businessTypeEnum = BusinessTypeEnum.INSERT_UPDATE)
    public RestResult<Boolean> edit(@RequestBody @Valid ApplicationTypeDto dto) {
        return RestResponse.ok(applicationTypeService.edit(dto));
    }
    @ApiOperation("应用类型列表")
    @GetMapping("applicationType/list")
    @ApiOperationSupport(order = 120)
    public RestResult<List<ApplicationTypeVo>> applicationTypeList() {
        return RestResponse.ok(applicationTypeService.applicationTypeList());
    }
    @ApiOperation("应用类型列表(分页)")
    @PostMapping("applicationType/page")
    @ApiOperationSupport(order = 130)
    public RestResult<IPage<ApplicationTypeVo>> applicationTypePage(@RequestBody ApplicationTypeSearch dto) {
        return RestResponse.ok(applicationTypeService.applicationTypePage(dto));
    }
    @ApiOperation("应用类型-删除")
    @DeleteMapping("applicationType/{applicationTypeId}")
    @ApiOperationSupport(order = 140)
    @Log(tag = LogTagEnum.APPLICATIONTYPE,title = "删除应用类型",businessTypeEnum = BusinessTypeEnum.DELETE)
    public RestResult<Boolean> applicationTypeDelete(@PathVariable(value = "applicationTypeId") Long applicationTypeId) {
        return RestResponse.ok(applicationTypeService.applicationTypeDelete(applicationTypeId));
    }
}
