package com.usoftchina.bi.server.dao.dashboard;

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 org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Mapper
@Repository
public interface DashboardFavoriteMapper {

    @Select("SELECT ID AS \"id\", BD_NAME AS \"name\" FROM BI_DASHBOARDS WHERE ID IN (SELECT DASHBOARD_ID FROM BI_DASHBOARDS_FAVORITE WHERE USER_ID = #{userId})")
    List<Map<String, String>> list(@Param("userId") int userId);

    @Insert("INSERT INTO BI_DASHBOARDS_FAVORITE(USER_ID, DASHBOARD_ID) VALUES(#{userId,jdbcType=INTEGER},#{dashboardId,jdbcType=INTEGER})")
    void insert(@Param("userId") int userId, @Param("dashboardId") int dashboardId);

    @Insert("DELETE FROM BI_DASHBOARDS_FAVORITE WHERE DASHBOARD_ID = #{dashboardId}")
    void remove(@Param("dashboardId") int dashboardId);
}
