<commit_before>﻿using System;
using System.Collections.Generic;

namespace LunaCommon.Locks
{
    /// <summary>
    /// Class that retrieve locks
    /// </summary>
    public partial class LockQuery
    {
        private LockStore LockStore { get; }

        public LockQuery(LockStore lockStore)
        {
            LockStore = lockStore;
        }

        /// <summary>
        /// Checks if the vessel based lock belongs to player
        /// </summary>
        public bool LockBelongsToPlayer(LockType type, Guid vesselId, string playerName)
        {
            switch (type)
            {
                case LockType.Control:
                    if (LockStore.ControlLocks.TryGetValue(vesselId, out var controlLock))
                        return controlLock.PlayerName == playerName;
                    break;
                case LockType.Update:
                    if (LockStore.UpdateLocks.TryGetValue(vesselId, out var updateLock))
                        return updateLock.PlayerName == playerName;
                    break;
                case LockType.UnloadedUpdate:
                    if (LockStore.UnloadedUpdateLocks.TryGetValue(vesselId, out var unloadedUpdateLock))
                        return unloadedUpdateLock.PlayerName == playerName;
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }

            return false;
        }

        /// <summary>
        /// Checks if the vessel based lock exists
        /// </summary>
        public bool LockExists(LockType type, Guid vesselId)
        {
            switch (type)
            {
                case LockType.Control:
                    return LockStore.ControlLocks.ContainsKey(vesselId);
                case LockType.Update:
                    return LockStore.UpdateLocks.ContainsKey(vesselId);
                case LockType.UnloadedUpdate:
                    return LockStore.UnloadedUpdateLocks.ContainsKey(vesselId);
                default:
                    throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }

        /// <summary>
        /// Get the vessel based lock owner
        /// </summary>
        private string GetLockOwner(LockType type, Guid vesselId)
        {
            switch (type)
            {
                case LockType.Control:
                    if (LockStore.ControlLocks.TryGetValue(vesselId, out var controlLock))
                        return controlLock.PlayerName;
                    break;
                case LockType.Update:
                    if (LockStore.UpdateLocks.TryGetValue(vesselId, out var updateLock))
                        return updateLock.PlayerName;
                    break;
                case LockType.UnloadedUpdate:
                    if (LockStore.UpdateLocks.TryGetValue(vesselId, out var unloadedUpdateLock))
                        return unloadedUpdateLock.PlayerName;
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }

            return null;
        }

        /// <summary>
        /// Get all the locks of a player
        /// </summary>
        public IEnumerable<LockDefinition> GetAllPlayerLocks(string playerName)
        {<commit_msg>Fixed lock query<commit_after>﻿using System;
using System.Collections.Generic;

namespace LunaCommon.Locks
{
    /// <summary>
    /// Class that retrieve locks
    /// </summary>
    public partial class LockQuery
    {
        private LockStore LockStore { get; }

        public LockQuery(LockStore lockStore)
        {
            LockStore = lockStore;
        }

        /// <summary>
        /// Checks if the vessel based lock belongs to player
        /// </summary>
        public bool LockBelongsToPlayer(LockType type, Guid vesselId, string playerName)
        {
            switch (type)
            {
                case LockType.Control:
                    if (LockStore.ControlLocks.TryGetValue(vesselId, out var controlLock))
                        return controlLock.PlayerName == playerName;
                    break;
                case LockType.Update:
                    if (LockStore.UpdateLocks.TryGetValue(vesselId, out var updateLock))
                        return updateLock.PlayerName == playerName;
                    break;
                case LockType.UnloadedUpdate:
                    if (LockStore.UnloadedUpdateLocks.TryGetValue(vesselId, out var unloadedUpdateLock))
                        return unloadedUpdateLock.PlayerName == playerName;
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }

            return false;
        }

        /// <summary>
        /// Checks if the vessel based lock exists
        /// </summary>
        public bool LockExists(LockType type, Guid vesselId)
        {
            switch (type)
            {
                case LockType.Control:
                    return LockStore.ControlLocks.ContainsKey(vesselId);
                case LockType.Update:
                    return LockStore.UpdateLocks.ContainsKey(vesselId);
                case LockType.UnloadedUpdate:
                    return LockStore.UnloadedUpdateLocks.ContainsKey(vesselId);
                default:
                    throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }

        /// <summary>
        /// Get the vessel based lock owner
        /// </summary>
        private string GetLockOwner(LockType type, Guid vesselId)
        {
            switch (type)
            {
                case LockType.Control:
                    if (LockStore.ControlLocks.TryGetValue(vesselId, out var controlLock))
                        return controlLock.PlayerName;
                    break;
                case LockType.Update:
                    if (LockStore.UpdateLocks.TryGetValue(vesselId, out var updateLock))
                        return updateLock.PlayerName;
                    break;
                case LockType.UnloadedUpdate:
                    if (LockStore.UnloadedUpdateLocks.TryGetValue(vesselId, out var unloadedUpdateLock))
                        return unloadedUpdateLock.PlayerName;
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }

            return null;
        }

        /// <summary>
        /// Get all the locks of a player
        /// </summary>
        public IEnumerable<LockDefinition> GetAllPlayerLocks(string playerName)
        {
{'fraction_non_alphanumeric': 0.07368890209478532, 'fraction_numerical': 0.0, 'mean_word_length': 1.4085867620751342, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '324500', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1536, 'n_words': 380}