You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
recyclarr/src/Recyclarr.Cli/Pipelines/QualityProfile/UpdatedFormatScore.cs

57 lines
2.0 KiB

using Recyclarr.Cli.Pipelines.QualityProfile.Models;
using Recyclarr.Cli.Pipelines.QualityProfile.PipelinePhases;
using Recyclarr.Common.Extensions;
using Recyclarr.ServarrApi.QualityProfile;
namespace Recyclarr.Cli.Pipelines.QualityProfile;
public enum FormatScoreUpdateReason
{
/// <summary>
/// A score who's value did not change.
/// </summary>
NoChange,
/// <summary>
/// A score that is changed.
/// </summary>
Updated,
/// <summary>
/// Scores were reset to a 0 value because `reset_unmatched_scores` was set to `true`.
/// </summary>
Reset,
/// <summary>
/// New custom format scores (format items) shouldn't exist normally. They do exist during
/// `--preview` runs since new custom formats that aren't synced yet won't be available when
/// processing quality profiles.
/// </summary>
New
}
public record UpdatedFormatScore(ProfileFormatItemDto Dto, int NewScore, FormatScoreUpdateReason Reason)
{
public static UpdatedFormatScore New(ProcessedQualityProfileScore score)
{
var dto = new ProfileFormatItemDto {Format = score.FormatId, Name = score.CfName};
return new UpdatedFormatScore(dto, score.Score, FormatScoreUpdateReason.New);
}
public static UpdatedFormatScore Reset(ProfileFormatItemDto dto, ProcessedQualityProfileData profileData)
{
var reset = profileData.Profile.ResetUnmatchedScores;
var shouldReset = reset.Enabled && reset.Except.All(x => !dto.Name.EqualsIgnoreCase(x));
var score = shouldReset ? 0 : dto.Score;
var reason = shouldReset ? FormatScoreUpdateReason.Reset : FormatScoreUpdateReason.NoChange;
return new UpdatedFormatScore(dto, score, reason);
}
public static UpdatedFormatScore Updated(ProfileFormatItemDto dto, ProcessedQualityProfileScore score)
{
var reason = dto.Score == score.Score ? FormatScoreUpdateReason.NoChange : FormatScoreUpdateReason.Updated;
return new UpdatedFormatScore(dto, score.Score, reason);
}
}