import 'package:json_annotation/json_annotation.dart';

part 'test_questions_image_info.g.dart';

@JsonSerializable()
class TestQuestionsImageInfo extends Object {
  @JsonKey(name: 'url')
  String url;

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

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

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

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

  @JsonKey(name: 'pixelRatio') // 像素比
  double pixelRatio;

  @JsonKey(name: 'scale')
  double? scale;

  @JsonKey(name: 'scaleHeight')
  double? scaleHeight;

  @JsonKey(name: 'scaleWidth')
  double? scaleWidth;

  double? imageHeightOffsetStart;

  double? imageHeightOffsetend;

  TestQuestionsImageInfo(
      {required this.width,
      required this.height,
      required this.url,
      required this.boxWidth,
      required this.boxHeight,
      this.pixelRatio = 1}) {
    // print('图片宽度：$width');
    // print('图片高度：$height');

    // print('容器宽度：$boxWidth');
    // print('容器高度：$boxHeight');

    pixelRatio = width / boxWidth;

    scale = boxWidth / width;
    scaleHeight = scale! * height;
    scaleWidth = scale! * width;

    if (scaleHeight != null) {
      imageHeightOffsetStart = (boxHeight - scaleHeight!) / 2;
      imageHeightOffsetend = imageHeightOffsetStart! + scaleHeight!;
    }
  }

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

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