package com.yuchen.saas.park.service.controller.building;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yuchen.saas.park.api.dto.building.PmgBatBuildingApartmentTypeQryDto;
import com.yuchen.saas.park.api.dto.building.PmgBatBuildingApartmentTypeQueryDto;
import com.yuchen.saas.park.api.entity.building.PmgBatBuildingApartmentType;
import com.yuchen.saas.park.api.vo.building.PmgBatBuildingApartmentTypeCountVO;
import com.yuchen.saas.park.service.service.building.IPmgBatBuildingApartmentTypeService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.web.bind.annotation.*;

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

/**
 *
 * 户型信息表 相关接口
 *
 *
 * @author yuanzhelin
 * @since 2024-10-17
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/pmgBatBuildingApartmentType")
public class PmgBatBuildingApartmentTypeController {

    @Resource
    private IPmgBatBuildingApartmentTypeService pmgBatBuildingApartmentTypeService;

    /**
     * 提交
     * @tag pauly-lyz
     */
    @PostMapping("/save")
    @ApiOperation(value = "提交")
    public R save(@Valid @RequestBody PmgBatBuildingApartmentType dto) {
        pmgBatBuildingApartmentTypeService.saveOrUpdate(dto);
        return R.success();
    }
    /**
     * 分页查询
     * @tag pauly-lyz
     */
    @PostMapping("/page")
    @ApiOperation(value = "分页查询")
    public R<IPage<PmgBatBuildingApartmentType>> page(@RequestBody PmgBatBuildingApartmentTypeQueryDto dto) {
        return R.data(pmgBatBuildingApartmentTypeService.pages(dto));
    }
    /**
     * 删除
     * @tag pauly-lyz
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除")
    public R delete(@PathVariable Long id) {
        return R.data(pmgBatBuildingApartmentTypeService.removeById(id));
    }
    /**
     * 详情
     * @tag pauly-lyz
     */
    @GetMapping("/detail/{id}")
    @ApiOperation(value = "详情")
    public R<PmgBatBuildingApartmentType> detail(@PathVariable Long id) {
        return R.data(pmgBatBuildingApartmentTypeService.getById(id));
    }

    //---------------------------------小程序用--------------------------------------
    @PostMapping("/app/list")
    @ApiOperation(value = "小程序查询户型列表")
    public R<List<PmgBatBuildingApartmentType>> list(@RequestBody PmgBatBuildingApartmentTypeQryDto dto) {
        return R.data(pmgBatBuildingApartmentTypeService.getList(dto));
    }
    @GetMapping("/app/typeCount")
    @ApiOperation(value = "小程序户型类型统计")
    public R<List<PmgBatBuildingApartmentTypeCountVO>> typeCount(@RequestParam Long projectId) {
        return R.data(pmgBatBuildingApartmentTypeService.typeCount(projectId));
    }
}
