//
//  NostaleMatePacketApi.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 NosSmooth.Core.Client;
using NosSmooth.Game.Attributes;
using NosSmooth.Packets.Client;
using NosSmooth.Packets.Enums.Entities;
using NosSmooth.Packets.Enums.NRun;
using Remora.Results;
namespace NosSmooth.Game.Apis;
/// 
/// Packet api for managing mates, company, stay, sending them back.
/// 
public class NostaleMatePacketApi
{
    private readonly INostaleClient _client;
    /// 
    /// Initializes a new instance of the  class.
    /// 
    /// The client.
    public NostaleMatePacketApi(INostaleClient client)
    {
        _client = client;
    }
    /// 
    /// Make the given pet your company (possible only in miniland).
    /// 
    /// 
    /// May be used only in miniland.
    ///
    /// Unsafe, does not check whether the mate exists
    /// or whether the character is in miniland.
    /// 
    /// The id of the mate to have company.
    /// The cancellation token used for cancelling the operation.
    /// A result that may or may not have succeeded.
    public async Task CompanyAsync(long mateId, CancellationToken ct = default)
        => await _client.SendPacketAsync
        (
            new NRunPacket
            (
                NRunType.Mate,
                (short)MateNRunType.Company,
                EntityType.Npc,
                mateId,
                null
            ),
            ct
        );
    /// 
    /// Make the given pet stay in your miniland (possible only in miniland).
    /// 
    /// 
    /// May be used only in miniland.
    ///
    /// Unsafe, does not check whether the mate exists
    /// or whether the character is in miniland.
    /// 
    /// The id of the mate to have company.
    /// The cancellation token used for cancelling the operation.
    /// A result that may or may not have succeeded.
    public async Task StayAsync(long mateId, CancellationToken ct = default)
        => await _client.SendPacketAsync
        (
            new NRunPacket
            (
                NRunType.Mate,
                (short)MateNRunType.Stay,
                EntityType.Npc,
                mateId,
                null
            ),
            ct
        );
    /// 
    /// Save the given pet back to miniland.
    /// 
    /// 
    /// Unsafe, does not check whether the mate exists.
    /// 
    /// The id of the mate to have company.
    /// The cancellation token used for cancelling the operation.
    /// A result that may or may not have succeeded.
    public async Task SendBackAsync(long mateId, CancellationToken ct = default)
        => await _client.SendPacketAsync
        (
            new NRunPacket
            (
                NRunType.Mate,
                (short)MateNRunType.RequestPetSendBack,
                EntityType.Npc,
                mateId,
                null
            ),
            ct
        );
}