package com.gxwebsoft.house.controller;

import com.gxwebsoft.common.core.annotation.OperationLog;
import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.common.core.web.BatchParam;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.house.entity.HouseAiConfig;
import com.gxwebsoft.house.param.HouseAiConfigParam;
import com.gxwebsoft.house.service.HouseAiConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * AI找房配置控制器
 */
@Tag(name = "AI找房配置管理")
@RestController
@RequestMapping("/api/house/ai-config")
public class HouseAiConfigController extends BaseController {

    @Resource
    private HouseAiConfigService houseAiConfigService;

    @Operation(summary = "分页查询AI找房配置")
    @GetMapping("/page")
    public ApiResult<PageResult<HouseAiConfig>> page(HouseAiConfigParam param) {
        return success(houseAiConfigService.pageRel(param));
    }

    @Operation(summary = "查询全部AI找房配置")
    @GetMapping()
    public ApiResult<List<HouseAiConfig>> list(HouseAiConfigParam param) {
        return success(houseAiConfigService.listRel(param));
    }

    @Operation(summary = "查询当前租户AI找房配置")
    @GetMapping("/current")
    public ApiResult<HouseAiConfig> current() {
        return success(houseAiConfigService.getCurrentConfig(getTenantId()));
    }

    @Operation(summary = "根据id查询AI找房配置")
    @GetMapping("/{id}")
    public ApiResult<HouseAiConfig> get(@PathVariable("id") Integer id) {
        return success(houseAiConfigService.getByIdRel(id));
    }

    @OperationLog
    @Operation(summary = "添加AI找房配置")
    @PostMapping()
    public ApiResult<?> save(@RequestBody HouseAiConfig houseAiConfig) {
        if (houseAiConfigService.save(houseAiConfig)) {
            return success("添加成功");
        }
        return fail("添加失败");
    }

    @OperationLog
    @Operation(summary = "修改AI找房配置")
    @PutMapping()
    public ApiResult<?> update(@RequestBody HouseAiConfig houseAiConfig) {
        if (houseAiConfigService.updateById(houseAiConfig)) {
            return success("修改成功");
        }
        return fail("修改失败");
    }

    @OperationLog
    @Operation(summary = "删除AI找房配置")
    @DeleteMapping("/{id}")
    public ApiResult<?> remove(@PathVariable("id") Integer id) {
        if (houseAiConfigService.removeById(id)) {
            return success("删除成功");
        }
        return fail("删除失败");
    }

    @OperationLog
    @Operation(summary = "批量修改AI找房配置")
    @PutMapping("/batch")
    public ApiResult<?> updateBatch(@RequestBody BatchParam<HouseAiConfig> batchParam) {
        if (batchParam.update(houseAiConfigService, "config_id")) {
            return success("修改成功");
        }
        return fail("修改失败");
    }

    @OperationLog
    @Operation(summary = "批量删除AI找房配置")
    @DeleteMapping("/batch")
    public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
        if (houseAiConfigService.removeByIds(ids)) {
            return success("删除成功");
        }
        return fail("删除失败");
    }
}
