import 'package:cinema/common/image_resizer.dart';
import 'package:cinema/feature/poster/domain/poster.enums.dart';
import 'package:zard/zard.dart';

final _orientations = PosterOrientation.values.map((e) => e.name);
final _formats = PosterFormat.values.map((e) => e.name);
final _outputs = PosterOutput.values.map((e) => e.name);

final posterSchema = z.map({
  'width': z.int().min(1, message: "'width' must be at least 1").max(4000, message: "'width' must be at most 4000").$default(ImageResizer.maxWidth),
  'height': z.int().min(1, message: "'height' must be at least 1").max(4000, message: "'height' must be a most 4000").$default(ImageResizer.maxHeight),
  'count': z.int().min(1, message: "'count' must be at least 1").max(20, message: "'count' must be at most 20").$default(4),
  'orientation': z.string().refine(
    (value) => _orientations.contains(value),
    message: "'orientation' must be either ${_orientations.join(', ')}",
  ).$default(PosterOrientation.horizontal.name),
  'shuffle': z.bool(message: "'shuffle' must be a boolean value").$default(true),
  'language': z.string(message: "'language' must be a string").transform((value) => value.trim()).$default("de"),
  'backgroundColor': z.string().regex(
    RegExp(r'^#([a-fA-F0-9]{3}|[a-fA-F0-9]{6})$'),
    message: "The 'backgroundColor' must be a valid hexadecimal color code (e.g., #000 or #FF0000)",
  ).$default("#000000"),
  'format': z.string().refine(
    (value) => _formats.contains(value),
    message: "'format' must be either ${_formats.join(', ')}",
  ).$default(PosterFormat.jpeg.name),
  'output': z.string().refine(
    (value) => _outputs.contains(value),
    message: "'output' must be either ${_outputs.join(', ')}",
  ).$default(PosterOutput.lvgl9Binary.name),
});
