/*
 * Copyright (c) 2025
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:splash_video/splash_video.dart';

void main() {
  group('VideoConfig', () {
    test('creates with default values', () {
      const config = VideoConfig();
      
      expect(config.playImmediately, isTrue);
      expect(config.scale, equals(VideoScaleMode.cover));
      expect(config.useSafeArea, isFalse);
      expect(config.volume, equals(80.0));
      expect(config.onPlayerInitialized, isNull);
    });

    test('creates with custom values', () {
      final config = VideoConfig(
        playImmediately: false,
        scale: VideoScaleMode.contain,
        useSafeArea: true,
        volume: 50.0,
        onPlayerInitialized: (player) {},
      );

      expect(config.playImmediately, isFalse);
      expect(config.scale, equals(VideoScaleMode.contain));
      expect(config.useSafeArea, isTrue);
      expect(config.volume, equals(50.0));
      expect(config.onPlayerInitialized, isNotNull);
    });

    test('backward compatibility: videoVisibilityEnum getter works', () {
      const config = VideoConfig(scale: VideoScaleMode.cover);
      // ignore: deprecated_member_use_from_same_package
      expect(config.videoVisibilityEnum, equals(VideoScaleMode.cover));
    });

    test('accepts volume range 0-100', () {
      const config1 = VideoConfig(volume: 0.0);
      const config2 = VideoConfig(volume: 100.0);
      const config3 = VideoConfig(volume: 50.0);

      expect(config1.volume, equals(0.0));
      expect(config2.volume, equals(100.0));
      expect(config3.volume, equals(50.0));
    });

    test('onPlayerInitialized callback can be invoked', () {
      var callbackInvoked = false;

      final config = VideoConfig(
        onPlayerInitialized: (player) {
          callbackInvoked = true;
        },
      );

      // Mock Player call - we can't create real Player in unit tests
      // because MediaKit requires native libraries
      expect(config.onPlayerInitialized, isNotNull);
      
      // Verify the callback is callable (just testing the API surface)
      if (config.onPlayerInitialized != null) {
        // We can't actually create a Player without MediaKit native libs
        // but we can verify the callback signature is correct
        expect(callbackInvoked, isFalse);
      }
    });
  });

  group('VideoFitMode', () {
    test('has all expected values', () {
      expect(VideoScaleMode.values.length, equals(7));
      expect(VideoScaleMode.values, contains(VideoScaleMode.fill));
      expect(VideoScaleMode.values, contains(VideoScaleMode.cover));
      expect(VideoScaleMode.values, contains(VideoScaleMode.contain));
      expect(VideoScaleMode.values, contains(VideoScaleMode.fitWidth));
      expect(VideoScaleMode.values, contains(VideoScaleMode.fitHeight));
      expect(VideoScaleMode.values, contains(VideoScaleMode.none));
      expect(VideoScaleMode.values, contains(VideoScaleMode.scaleDown));
    });

    test('values are unique', () {
      final values = VideoScaleMode.values.toSet();
      expect(values.length, equals(VideoScaleMode.values.length));
    });

    test('converts correctly to BoxFit', () {
      expect(VideoScaleMode.fill.toBoxFit(), equals(BoxFit.fill));
      expect(VideoScaleMode.cover.toBoxFit(), equals(BoxFit.cover));
      expect(VideoScaleMode.contain.toBoxFit(), equals(BoxFit.contain));
      expect(VideoScaleMode.fitWidth.toBoxFit(), equals(BoxFit.fitWidth));
      expect(VideoScaleMode.fitHeight.toBoxFit(), equals(BoxFit.fitHeight));
      expect(VideoScaleMode.none.toBoxFit(), equals(BoxFit.none));
      expect(VideoScaleMode.scaleDown.toBoxFit(), equals(BoxFit.scaleDown));
    });
  });
}
