package com.sptg.gateway.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.estate.api.dto.FloorDto;
import com.sptg.estate.api.dto.RoomDto;
import com.sptg.estate.api.entity.Floor;
import com.sptg.estate.api.entity.Room;
import com.sptg.estate.api.feigns.RoomFeign;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/grid/room")
public class RoomController {

    private final RoomFeign roomFeign;

    @GetMapping(value = "/syncRoom/{residentialId}")
    public List<Room> syncRoom(@PathVariable("residentialId")Long residentialId){
        Page<Room> page = new Page<>();
        page.setCurrent(1);
        page.setSize(999999999);
        RoomDto roomDto = new RoomDto();
        roomDto.setPage(page);
        roomDto.setResidentialId(residentialId);
        ResultBean<Page<Room>> pageResultBean = this.roomFeign.showRoomList(roomDto);
        if(pageResultBean !=null){
            if(pageResultBean.getData()!=null){
                return pageResultBean.getData().getRecords();
            }
        }
        return null;
    }

    /**
     * 功能描述:房间列表查询
     * @param roomDto 房间业务对象（含查询条件）
     * @param page 分页条件
     * @return ResultBean<Page<Room>>
     *
     *
     */
    @GetMapping(value = "/showRoomList")
    public ResultBean<Page<Room>> showRoomList(RoomDto roomDto, Page<Room> page) {
        // 暂时拿全部的数据
//        residentialDto.setOrgPosition("0/1/");
        roomDto.setPage(page);
        return this.roomFeign.showRoomList(roomDto);
    }

    @GetMapping(value = "/findRoomById/{id}")
    public ResultBean<Room> findRoomById(@PathVariable(value = "id") Long id){
        Room room = this.roomFeign.findRoomById(id);
        Assert.notNull(room,"房间不存在");
        return new ResultBean<>(ResultEnum.SUCCESS,room);
    }

}
