package com.nursinghome.mapper;

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

import java.util.List;

@Mapper
public interface FamilyElderMapper {
    @Insert("INSERT INTO family_elder(family_id, elder_id, relationship, created_at) VALUES(#{familyId}, #{elderId}, #{relationship}, NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(FamilyElder relation);

    @Select("SELECT * FROM family_elder WHERE family_id = #{familyId}")
    List<FamilyElder> listByFamilyId(Long familyId);

    @Select("SELECT * FROM family_elder WHERE family_id = #{familyId} AND elder_id = #{elderId} LIMIT 1")
    FamilyElder findByFamilyAndElder(@Param("familyId") Long familyId, @Param("elderId") Long elderId);
}
