package com.test.mapper;

import com.test.bean.Order;
import org.apache.ibatis.annotations.*;

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

@Mapper
public interface OrderMapper {
    @Select("select * from order_info")
    ArrayList<Order> getAllOrder();


    @Select("select * from order_info where order_id = #{id}")
    Order getOrderById(Long id);

    @Insert("INSERT INTO order_info(status, room_type_id, user_id_json, price, begin_time, end_time, create_time, update_time) " +
            "VALUES (#{status}, #{roomTypeId}, #{userIdJson}, #{price}, #{beginTime}, #{endTime}, #{createTime}, #{updateTime})")
    boolean createOrder(Order order);

    @Update("update order_info set status = 1, update_time = #{now}")
    int checkoutOrder(Long id, LocalDateTime now);

    @Update("update order_info set room_type_id = #{roomTypeId}, user_id_json = #{userIdJson}, price = #{price}, begin_time = #{beginTime}, end_time = #{endTime} where order_id = #{orderId}")
    int updateOrder(Order order);
}
