package com.pandoli365.bibimbap.mapper;

import com.pandoli365.bibimbap.data.BadgeData;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BadgesMapper {

    @Insert("""
            INSERT INTO badges (badge_key, display_name, description, badge_type, is_active)
            VALUES (#{badgeKey}, #{displayName}, #{description}, #{badgeType}, true)
            ON CONFLICT (badge_key) DO NOTHING
            """)
    int insertIgnore(@Param("badgeKey") String badgeKey,
                     @Param("displayName") String displayName,
                     @Param("description") String description,
                     @Param("badgeType") String badgeType);

    @Select("""
            SELECT
                badge_key AS "badgeKey",
                display_name AS "displayName",
                description AS "description",
                badge_type AS "badgeType",
                is_active AS "isActive"
            FROM badges
            WHERE is_active = true
            ORDER BY id
            """)
    List<BadgeData> listActive();
}
