//
// ItemInfoCommand.cs
//
// Copyright (c) František Boháček. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Extensions.Logging;
using NosSmooth.Data.Abstractions;
using NosSmooth.Data.Abstractions.Language;
using Remora.Commands.Attributes;
using Remora.Commands.Groups;
using Remora.Results;
namespace DataBrowser.Commands;
///
/// Command for getting information about an item.
///
public class ItemInfoCommand : CommandGroup
{
private readonly IInfoService _infoService;
private readonly ILanguageService _languageService;
///
/// Initializes a new instance of the class.
///
/// The info service.
/// The language service.
public ItemInfoCommand(IInfoService infoService, ILanguageService languageService)
{
_infoService = infoService;
_languageService = languageService;
}
///
/// Gets the info about the specified item.
///
/// The vnum of the item.
/// The language.
/// A result that may or may not succeeded.
[Command("item")]
public async Task HandleItemInfo(int vnum, Language language = Language.Uk)
{
var itemResult = await _infoService.GetItemInfoAsync(vnum, CancellationToken);
if (!itemResult.IsSuccess)
{
return Result.FromError(itemResult);
}
var translationResult = await _languageService.GetTranslationAsync
(itemResult.Entity.Name, language, CancellationToken);
if (!translationResult.IsSuccess)
{
return Result.FromError(translationResult);
}
Console.WriteLine("Found item {0}", translationResult.Entity);
Console.WriteLine(" Type: {0}", itemResult.Entity.Type);
Console.WriteLine(" SubType: {0}", itemResult.Entity.SubType);
Console.WriteLine(" BagType: {0}", itemResult.Entity.BagType);
Console.WriteLine(" Data: {0}", string.Join('|', itemResult.Entity.Data));
return Result.FromSuccess();
}
}