package com.nursinghome.mapper;

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

import java.util.List;

@Mapper
public interface FeedbackMapper {
    @Insert("INSERT INTO feedback(family_id, elder_id, type, content, rating, status, created_at, updated_at) VALUES(#{familyId}, #{elderId}, #{type}, #{content}, #{rating}, #{status}, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Feedback feedback);

    @Select("SELECT * FROM feedback ORDER BY created_at DESC")
    List<Feedback> listAll();

    @Select("SELECT * FROM feedback WHERE family_id = #{familyId} ORDER BY created_at DESC")
    List<Feedback> listByFamilyId(Long familyId);

    @Update("UPDATE feedback SET status=#{status}, reply=#{reply}, updated_at=NOW() WHERE id=#{id}")
    int updateStatus(Feedback feedback);
}
