import 'package:json_annotation/json_annotation.dart';

part 'do_test_questions_image_info.g.dart';

@JsonSerializable()
class TestQuestionsImageInfo extends Object {
  @JsonKey(name: 'templateId')
  int? templateId;

  @JsonKey(name: 'boxHeight')
  double boxHeight;

  @JsonKey(name: 'boxWidth')
  double boxWidth;

  @JsonKey(name: 'imageWidth') // 图片原始宽
  double imageWidth;

  @JsonKey(name: 'imageHeight') // 图片原始高
  double imageHeight;

  @JsonKey(name: 'url')
  String url;

  @JsonKey(name: 'actualImgWidth') // 实际展示图片宽度
  double actualImgWidth;

  @JsonKey(name: 'actualImgHeight') // 实际展示图片高度
  double actualImgHeight;

  @JsonKey(name: 'remainingHeight') // 视图剩余高度 实际展示图片展示高度下 剩余高度.(若为负数就是超出视图的高度值)
  double remainingHeight;

  @JsonKey(name: 'imageHeightOffsetStart') // 顶部坐标Y
  double imageHeightOffsetStart;

  @JsonKey(name: 'imageHeightOffsetend') // 底部坐标Y
  double imageHeightOffsetend;

  // 基准
  @JsonKey(name: 'scaleRatio')
  double scaleRatio;

  // 缩放比例
  @JsonKey(name: 'zoom')
  double zoom;

  TestQuestionsImageInfo({
    required this.url,
    required this.boxWidth,
    required this.boxHeight,
    required this.imageWidth,
    required this.imageHeight,
    this.templateId,
    this.scaleRatio = 1,
    this.zoom = 1,
    this.actualImgWidth = 0,
    this.actualImgHeight = 0,
    this.remainingHeight = 0,
    this.imageHeightOffsetStart = 0,
    this.imageHeightOffsetend = 0,
  }) {
    // 图片已视图宽为基准，高度自适应可滑动   图片的实际宽高都需要乘此基准值
    scaleRatio = boxWidth / imageWidth;
    actualImgWidth = imageWidth * scaleRatio * zoom;
    actualImgHeight = imageHeight * scaleRatio * zoom;
    remainingHeight = boxHeight - actualImgHeight;
    imageHeightOffsetStart = remainingHeight / 2;
    imageHeightOffsetend = imageHeightOffsetStart + actualImgHeight;
  }

  factory TestQuestionsImageInfo.fromJson(Map<String, dynamic> srcJson) => _$TestQuestionsImageInfoFromJson(srcJson);

  Map<String, dynamic> toJson() => _$TestQuestionsImageInfoToJson(this);
}
