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.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) {
        return houseResourceService.updateHouseResource(dto);
    }

    @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 pageHouseResources(HouseResourcePageQuery query) {
        return AjaxResult.success(houseResourceService.pageHouseResources(query));
    }

}
