import 'package:json_annotation/json_annotation.dart';

part 'chat_background_settings.g.dart';

/// Source of the chat background.
/// * [pattern] — the bundled tiled asset (legacy default, dark-mode inverted)
/// * [image] — a user-picked image stored at [AppPaths.chatBackgroundImage]
/// * [color] — a single solid colour ([ChatBackgroundSettings.colorValue])
/// * [none] — plain theme surface colour
enum ChatBackgroundType { pattern, image, color, none }

/// How [ChatBackgroundType.pattern]/[ChatBackgroundType.image] fill the area.
enum ChatBackgroundFit { cover, tile, center }

@JsonSerializable()
class ChatBackgroundSettings {
  ChatBackgroundType type;
  ChatBackgroundFit fit;

  /// ARGB colour for [ChatBackgroundType.color]; null until the user picks one.
  int? colorValue;

  /// Monotonically increasing cache-buster. The image lives under a constant
  /// filename, so Flutter's [ImageCache] can't tell a replacement apart — this
  /// counter drives a [ValueKey] that forces a fresh subtree after a swap.
  int imageVersion;

  /// Strength of the black dim overlay drawn above the background (0..1).
  double dim;

  /// Gaussian blur sigma applied to the pattern/image layer (0..~25).
  double blur;

  ChatBackgroundSettings({
    required this.type,
    required this.fit,
    required this.colorValue,
    required this.imageVersion,
    required this.dim,
    required this.blur,
  });

  factory ChatBackgroundSettings.fromJson(Map<String, dynamic> json) =>
      _$ChatBackgroundSettingsFromJson(json);
  Map<String, dynamic> toJson() => _$ChatBackgroundSettingsToJson(this);
}
