package com.ruoyi.web.controller.house;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.house.HouseResource;
import com.ruoyi.system.domain.house.vo.HouseResourcePageQuery;
import com.ruoyi.system.domain.house.vo.HouseResourceSaveUpdateDto;
import com.ruoyi.system.domain.house.vo.PageBusinessEntityStatisticsQuery;
import com.ruoyi.system.service.house.HouseResourceService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/house")
public class HouseResourceController {

    private final HouseResourceService houseResourceService;

    public HouseResourceController(HouseResourceService houseResourceService) {
        this.houseResourceService = houseResourceService;
    }

    @PostMapping
    public AjaxResult saveHouseResource(@RequestBody HouseResourceSaveUpdateDto dto) {
        houseResourceService.saveHouseResource(dto);
        return AjaxResult.success();
    }

    @GetMapping
    public AjaxResult queryHouseResourceById(@RequestParam String id) {
        return AjaxResult.success(houseResourceService.queryHouseResourceById(id));
    }

    @PutMapping
    public AjaxResult updateHouseResource(@RequestBody HouseResourceSaveUpdateDto dto) {
        houseResourceService.updateHouseResource(dto);
        return AjaxResult.success();
    }

    @DeleteMapping
    public AjaxResult deleteHouseResourceById(@RequestParam String id) {
        houseResourceService.deleteHouseResourceById(id);
        return AjaxResult.success();
    }

    @PostMapping("/batch")
    public AjaxResult batchSaveHouseResources(@RequestBody List<HouseResource> houseResources) {
        houseResourceService.batchSaveHouseResources(houseResources);
        return AjaxResult.success();
    }

    @GetMapping("/page")
    public AjaxResult getPageHouseResources(HouseResourcePageQuery query) {
        return AjaxResult.success(houseResourceService.pageHouseResources(query));
    }

    @GetMapping("/profileGraph")
    public AjaxResult getProfileGraphHouseResources(HouseResourcePageQuery query) {
        return AjaxResult.success(houseResourceService.profileGraphHouseResources(query));
    }

    @GetMapping("/list")
    public AjaxResult getListHouseResources(HouseResourcePageQuery query) {
        return AjaxResult.success(houseResourceService.listHouseResources(query));
    }

    @GetMapping("/businessEntityStatistics")
    public AjaxResult getBusinessEntityStatistics(HouseResourcePageQuery query) {
        return AjaxResult.success(houseResourceService.businessEntityStatistics(query));
    }

    @PostMapping("/page/businessEntityStatistics")
    public AjaxResult getPageBusinessEntityStatistics(@RequestBody PageBusinessEntityStatisticsQuery query) {
        return AjaxResult.success(houseResourceService.pageBusinessEntityStatistics(query));
    }
}
