import 'package:flutter/material.dart';
import 'package:flut/flut/object.dart';
import 'package:flut/flut/error.dart';

class FlutScrollPosition extends FlutRealtimeObject<ScrollPosition> {
  FlutScrollPosition.wrap({
    required super.runtime,
    required super.oid,
    required super.target,
  }) : super.wrap(type: 'ScrollPosition');

  @override
  dynamic getRawProperty(String property) {
    switch (property) {
      case 'pixels':
        return flutTarget.pixels;
      case 'minScrollExtent':
        return flutTarget.minScrollExtent;
      case 'maxScrollExtent':
        return flutTarget.maxScrollExtent;
      case 'viewportDimension':
        return flutTarget.viewportDimension;
      case 'hasContentDimensions':
        return flutTarget.hasContentDimensions;
      case 'hasPixels':
        return flutTarget.hasPixels;
      case 'atEdge':
        return flutTarget.atEdge;
    }
    throw FlutUnknownPropertyException('ScrollPosition', property);
  }

  @override
  bool setProperty(String property, dynamic value) {
    throw FlutUnknownPropertyException('ScrollPosition', property);
  }

  @override
  dynamic callMethod(String method, Map<String, dynamic> args) {
    switch (method) {
      case 'jumpTo':
        final offset = (args['offset'] as num).toDouble();
        flutTarget.jumpTo(offset);
        return true;
      case 'animateTo':
        final offset = (args['offset'] as num).toDouble();
        final duration = flutRuntime.decodeObject<Duration>(args['duration'])!;
        final curve = flutRuntime.decodeObject<Curve>(args['curve'])!;
        flutTarget.animateTo(offset, duration: duration, curve: curve);
        return true;
    }
    throw FlutUnknownMethodException(method);
  }
}
