using FastEndpoints;
using TaxBaik.Application.Services;

namespace TaxBaik.Web.Endpoints.SiteSettings;

public class SaveSiteSettingsRequest
{
    public string Phone { get; set; } = string.Empty;
    public string Email { get; set; } = string.Empty;
    public string KakaoUrl { get; set; } = string.Empty;
    public string InstagramUrl { get; set; } = string.Empty;
}

public class SaveResponse
{
    public string Message { get; set; } = string.Empty;
}

public class SaveEndpoint : Endpoint<SaveSiteSettingsRequest, SaveResponse>
{
    private readonly SiteSettingService _siteSettingService;

    public SaveEndpoint(SiteSettingService siteSettingService)
    {
        _siteSettingService = siteSettingService;
    }

    public override void Configure()
    {
        Put("/api/sitesettings");
        Policies("Bearer");
    }

    public override async Task HandleAsync(SaveSiteSettingsRequest request, CancellationToken ct)
    {
        if (request == null)
        {
            ThrowError("요청 본문이 비어 있습니다.");
        }

        await _siteSettingService.SaveAsync(request.Phone, request.Email, request.KakaoUrl, request.InstagramUrl, ct);

        await SendAsync(new SaveResponse
        {
            Message = "사이트 설정이 저장되었습니다."
        }, 200, cancellation: ct);
    }
}
