package com.pandoli365.bibimbap.mapper;

import com.pandoli365.bibimbap.data.GameLikeData;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface GameLikesMapper {

    @Select("""
            SELECT
                id,
                game_id AS gameId,
                user_key AS userKey,
                created_at AS createdAt
            FROM game_likes
            WHERE id = #{id}
            """)
    GameLikeData getGameLike(long id);

    @Insert("""
            INSERT INTO game_likes (
                game_id,
                user_key
            ) VALUES (
                #{gameId},
                #{userKey}
            )
            """)
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    int addGameLike(GameLikeData gameLike);

    @Update("""
            UPDATE game_likes
            SET
                game_id = #{gameId},
                user_key = #{userKey}
            WHERE id = #{id}
            """)
    int updateGameLike(GameLikeData gameLike);
}
