package com.alttd.altitudeweb.database.luckperms;

import com.alttd.altitudeweb.type_handler.UUIDTypeHandler;
import org.apache.ibatis.annotations.*;

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

public interface TeamMemberMapper {
    @ConstructorArgs({
            @Arg(column = "username", javaType = String.class),
            @Arg(column = "uuid", javaType = UUID.class, typeHandler = UUIDTypeHandler.class)
    })
    @Select("""
            SELECT players.username, players.uuid
            FROM luckperms_user_permissions AS permissions
            INNER JOIN luckperms_players AS players ON players.uuid = permissions.uuid
            WHERE permission = #{groupPermission} AND server = 'global'
            AND world = 'global'
            """)
    List<Player> getTeamMembers(@Param("groupPermission") String groupPermission);

    @ConstructorArgs({
            @Arg(column = "username", javaType = String.class),
            @Arg(column = "uuid", javaType = UUID.class, typeHandler = UUIDTypeHandler.class),
            @Arg(column = "group", javaType = String.class)
    })
    @Select("""
        SELECT players.username, players.uuid, permissions.permission AS 'group'
        FROM luckperms_user_permissions AS permissions
        INNER JOIN luckperms_players AS players ON players.uuid = permissions.uuid
        WHERE permission IN (${groupPermissions})
          AND server = 'global'
          AND world = 'global'
        """)
    List<PlayerWithGroup> getTeamMembersOfGroupList(@Param("groupPermissions") String groupPermissions);

}
