package com.nursinghome.mapper;

import com.nursinghome.entity.Elder;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ElderMapper {
    @Select("SELECT * FROM elder ORDER BY id DESC")
    List<Elder> listAll();

    @Select("SELECT * FROM elder WHERE id = #{id}")
    Elder findById(Long id);

    @Select("SELECT * FROM elder WHERE id_card = #{idCard} LIMIT 1")
    Elder findByIdCard(String idCard);

    @Insert("INSERT INTO elder(name, gender, id_card, birthday, room_no, check_in_date, care_level, status, remark) VALUES(#{name}, #{gender}, #{idCard}, #{birthday}, #{roomNo}, #{checkInDate}, #{careLevel}, #{status}, #{remark})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Elder elder);

    @Update("UPDATE elder SET name=#{name}, gender=#{gender}, id_card=#{idCard}, birthday=#{birthday}, room_no=#{roomNo}, check_in_date=#{checkInDate}, care_level=#{careLevel}, status=#{status}, remark=#{remark} WHERE id=#{id}")
    int update(Elder elder);

    @Delete("DELETE FROM elder WHERE id=#{id}")
    int delete(Long id);
}
