using StellaOps.Feedser.Core.Jobs;

namespace StellaOps.Feedser.WebService.Jobs;

public sealed record JobDefinitionResponse(
    string Kind,
    bool Enabled,
    string? CronExpression,
    TimeSpan Timeout,
    TimeSpan LeaseDuration,
    JobRunResponse? LastRun)
{
    public static JobDefinitionResponse FromDefinition(JobDefinition definition, JobRunSnapshot? lastRun)
    {
        return new JobDefinitionResponse(
            definition.Kind,
            definition.Enabled,
            definition.CronExpression,
            definition.Timeout,
            definition.LeaseDuration,
            lastRun is null ? null : JobRunResponse.FromSnapshot(lastRun));
    }
}
