package com.pandoli365.bibimbap.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface ReputationEventsMapper {

    @Insert("""
            INSERT INTO reputation_events (user_id, event_type, source_ref)
            VALUES (#{userId}, #{eventType}, #{sourceRef})
            ON CONFLICT (user_id, event_type, source_ref) WHERE source_ref IS NOT NULL DO NOTHING
            """)
    int insertIgnore(@Param("userId") long userId,
                     @Param("eventType") String eventType,
                     @Param("sourceRef") String sourceRef);

    @Select("""
            SELECT COUNT(*)
            FROM reputation_events
            WHERE user_id = #{userId}
              AND event_type = #{eventType}
            """)
    long countActive(@Param("userId") long userId, @Param("eventType") String eventType);
}
