package com.alttd.altitudeweb.database.proxyplaytime;

import com.alttd.altitudeweb.type_handler.UUIDTypeHandler;
import org.apache.ibatis.annotations.Arg;
import org.apache.ibatis.annotations.ConstructorArgs;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.UUID;

public interface StaffPlaytimeMapper {
    @ConstructorArgs({
            @Arg(column = "uuid", javaType = UUID.class, typeHandler = UUIDTypeHandler.class),
            @Arg(column = "serverName", javaType = String.class),
            @Arg(column = "sessionStart", javaType = long.class),
            @Arg(column = "sessionEnd", javaType = long.class)
    })
    @Select("""
        SELECT uuid,
               server_name AS serverName,
               session_start AS sessionStart,
               session_end   AS sessionEnd
        FROM sessions
        WHERE session_end > #{from}
          AND session_start < #{to}
          AND uuid IN (${staffUUIDs})
        ORDER BY uuid, session_start
        """)
    List<StaffPt> getSessionsDuring(@Param("from") long from,
                                    @Param("to") long to,
                                    @Param("staffUUIDs") String staffUUIDs);
}
