using Recyclarr.Cli.Pipelines.QualityProfile.Models; using Recyclarr.Common.Extensions; using Recyclarr.ServarrApi.QualityProfile; namespace Recyclarr.Cli.Pipelines.QualityProfile; public enum FormatScoreUpdateReason { /// /// A score who's value did not change. /// NoChange, /// /// A score that is changed. /// Updated, /// /// Scores were reset to a 0 value because `reset_unmatched_scores` was set to `true`. /// Reset, /// /// 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. /// 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); } }