using System.Threading;
using System.Threading.Tasks;
using MarcusLaw.OutlookAddin.Core.Models;

namespace MarcusLaw.OutlookAddin.Core.Services
{
    public interface IEspoCrmClient
    {
        Task<FileEmailResponse> FileMailAsync(FileEmailRequest request, CancellationToken cancellationToken = default);
        Task<SearchResult> GlobalSearchAsync(string query, CancellationToken cancellationToken = default);
        Task<System.Collections.Generic.List<EmailAddressMatch>> EmailAddressSearchAsync(string emailAddress, string? entityType = null, CancellationToken cancellationToken = default);
        Task<CaseEntity> GetCaseAsync(string id, string? select = null, CancellationToken cancellationToken = default);
        Task<AccountEntity> GetAccountAsync(string id, string? select = null, CancellationToken cancellationToken = default);
        Task<ContactEntity> GetContactAsync(string id, string? select = null, CancellationToken cancellationToken = default);
        Task<ContactEntity> CreateContactAsync(string name, string? emailAddress = null, CancellationToken cancellationToken = default);
        Task<EspoListResponse<CaseEntity>> ListCasesForContactAsync(string contactId, int maxSize = 5, CancellationToken cancellationToken = default);
        Task<UserInfo> TestConnectionAsync(CancellationToken cancellationToken = default);

        Task<AttachmentEntity> UploadAttachmentAsync(string fileName, string contentType, string base64Content, CancellationToken cancellationToken = default);
        Task<DocumentEntity> CreateDocumentAsync(string name, string attachmentFileId, string? parentType, string? parentId, string? folderId, CancellationToken cancellationToken = default);
        Task<EspoListResponse<DocumentFolder>> ListDocumentFoldersAsync(CancellationToken cancellationToken = default);
        Task<System.Collections.Generic.List<DocumentFolder>> ListFoldersUsedInCaseAsync(string caseId, CancellationToken cancellationToken = default);

        // Marcus-Law NetworkStorageIntegration endpoints (filesystem-based
        // folder structure under the case folder).
        Task EnsureCaseSubfoldersAsync(string caseId, CancellationToken cancellationToken = default);
        Task<System.Collections.Generic.List<NetworkStorageItem>> ListNetworkStorageFolderAsync(string path, CancellationToken cancellationToken = default);
        Task UploadAttachmentToNetworkStorageAsync(string attachmentId, string targetPath, CancellationToken cancellationToken = default);
    }
}
