using Indotalent.ConfigBackEnd.Interfaces;
using Indotalent.ConfigFrontEnd.Common;
using Indotalent.Features.Setting.AutoNumberSequence.Cqrs;
using Indotalent.Infrastructure.Authentication.Identity;
using Indotalent.Shared.Models;
using Microsoft.AspNetCore.Components;
using MudBlazor;
using RestSharp;

namespace Indotalent.Features.Setting.AutoNumberSequence;

public class AutoNumberSequenceService : BaseService
{
    private readonly RestClient _client;

    public AutoNumberSequenceService(
            IHttpClientFactory clientFactory,
            NavigationManager nav,
            ISnackbar snackbar,
            ICurrentUserService currentUserService,
            TokenProvider tokenProvider)
            : base(clientFactory, nav, snackbar, currentUserService, tokenProvider)
    {
        _client = new RestClient(nav.BaseUri);
    }

    public async Task<ApiResponse<List<GetAutoNumberSequenceListResponse>>?> GetAutoNumberSequenceListAsync()
    {
        var request = new RestRequest("api/auto-number-sequences", Method.Get);
        return await ExecuteWithResponseAsync<List<GetAutoNumberSequenceListResponse>>(_client, request);
    }

    public async Task<ApiResponse<UpdateAutoNumberSequenceResponse>?> UpdateAutoNumberSequenceAsync(UpdateAutoNumberSequenceRequest data)
    {
        var request = new RestRequest("api/auto-number-sequences/update", Method.Post);
        request.AddJsonBody(data);
        return await ExecuteWithResponseAsync<UpdateAutoNumberSequenceResponse>(_client, request);
    }
}