using TaxBaik.Domain.Entities;
using TaxBaik.Domain.Interfaces;

namespace TaxBaik.Application.Services;

public class SiteSettingService(ISiteSettingRepository repository)
{
    public Task<IReadOnlyDictionary<string, string>> GetAllAsync(CancellationToken ct = default)
        => repository.GetAllAsync(ct);

    public Task SaveAsync(string phone, string email, string kakaoUrl, string instagramUrl, CancellationToken ct = default)
    {
        var settings = new[]
        {
            new SiteSetting { Key = "PhoneNumber", Value = phone.Trim(), UpdatedAt = DateTime.UtcNow },
            new SiteSetting { Key = "EmailAddress", Value = email.Trim(), UpdatedAt = DateTime.UtcNow },
            new SiteSetting { Key = "KakaoChannelUrl", Value = kakaoUrl.Trim(), UpdatedAt = DateTime.UtcNow },
            new SiteSetting { Key = "InstagramUrl", Value = instagramUrl.Trim(), UpdatedAt = DateTime.UtcNow },
        };

        return repository.UpsertAsync(settings, ct);
    }
}
