package com.test.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.test.bean.PageBean;
import com.test.bean.RoomType;
import com.test.mapper.RoomTypeMapper;
import com.test.service.RoomTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;

@Service
public class RoomTypeServiceImpl implements RoomTypeService {

    @Autowired
    RoomTypeMapper roomTypeMapper;

    @Override
    public PageBean getRoomTypeByPage(int page, int pageSize) {
        PageHelper.startPage(page, pageSize);
        ArrayList<RoomType> roomType = roomTypeMapper.getRoomType();
        Page<RoomType> roomTypePage = (Page<RoomType>) roomType;
        return new PageBean(roomTypePage.getTotal(), roomTypePage.getResult());
    }

    @Override
    public boolean addRoomType(RoomType roomType) {
        roomType.setCreateTime(LocalDateTime.now());
        roomType.setUpdateTime(LocalDateTime.now());
        return roomTypeMapper.addRoomType(roomType);
    }

    @Override
    public RoomType getRoomTypeById(Long id) {
        return roomTypeMapper.getRoomTypeById(id);
    }

    @Override
    public boolean updateRoomType(RoomType roomType) {
        roomType.setUpdateTime(LocalDateTime.now());
        return roomTypeMapper.updateRoomType(roomType);
    }

    @Override
    public boolean deleteRoomType(Long id) {
        return roomTypeMapper.deleteRoomType(id);
    }

}
