using System.Text.Json;
using Tiku.Application.Jobs;

namespace Tiku.Api.Contracts;

public sealed class CreateBackgroundJobDto
{
    public string JobType { get; set; } = string.Empty;
    public JsonElement Payload { get; set; }
    public DateTimeOffset? RunAfter { get; set; }
    public int MaxRetries { get; set; } = 3;

    public CreateBackgroundJobCommand ToCommand(Guid tenantId)
    {
        return new CreateBackgroundJobCommand(
            tenantId,
            JobType,
            Payload.ValueKind == JsonValueKind.Undefined ? JsonSerializer.SerializeToElement(new { }) : Payload,
            RunAfter,
            MaxRetries);
    }
}
