import 'dart:developer';

import 'package:flutter_dotenv/flutter_dotenv.dart';

class AppConstants {
  // API Configuration aus Environment
  static String get apiBaseUrl =>
      dotenv.env['API_BASE_URL'] ?? 'https://slift.patanix.de';

  static String get apiVersion => dotenv.env['API_VERSION'] ?? 'v1';

  static String get environment => dotenv.env['ENVIRONMENT'] ?? 'production';

  static bool get isDebugMode =>
      dotenv.env['DEBUG_MODE']?.toLowerCase() == 'true';

  // Helper Getter
  static bool get isDevelopment => environment == 'development';
  static bool get isProduction => environment == 'production';

  // Debug Info
  static void printConfig() {
    log('═══════════════════════════════════');
    log('🔧 APP CONFIGURATION');
    log('Environment: $environment');
    log('API Base URL: $apiBaseUrl');
    log('API Version: $apiVersion');
    log('Debug Mode: $isDebugMode');
    log('═══════════════════════════════════');
  }
  // API Configuration
  // static const String apiBaseUrl = 'http://10.0.2.2:8090'; // Android emulator
  // static const String apiBaseUrl = 'https://slift.patanix.de';
  // static const String apiVersion = 'v1';

  // Wendler 5/3/1 Constants
  static const double trainingMaxPercentage = 0.9;
  static const double upperBodyIncrement = 2.5; // kg
  static const double lowerBodyIncrement = 5.0; // kg

  // XP System
  static const int baseXP = 1000;
  static const double xpMultiplier = 1.25;
  static const int maxLevel = 100;

  // XP Rewards
  static const int workoutCompleteXP = 100;
  static const double volumeXPRate = 0.01; // XP per kg
  static const int amrapBonusXPPerRep = 25;
  static const int prBonusXP = 200;
  static const int cycleCompleteXP = 500;

  // Rounding Steps
  static const double squatRoundingStep = 2.5;
  static const double calisthenicsRoundingStep = 1.25;

  // Default Inventory
  static const double defaultBarWeight = 20.0;
  static const List<double> defaultPlates = [
    25,
    25,
    20,
    20,
    15,
    15,
    10,
    10,
    5,
    5,
    2.5,
    2.5,
    1.25,
    1.25
  ];

  // Resistance Bands (Color: Resistance in KG approx)
  // Negative values imply assistance force
  static const Map<String, double> defaultBands = {
    'Blue': 30.0,
    'Green': 20.0,
    'Orange': 10.0,
    'Red': 5.0,
  };

  // Bodyweight Limits
  static const double minBodyweight = 40.0;
  static const double maxBodyweight = 200.0;

  // Animation Durations
  static const Duration shortAnimation = Duration(milliseconds: 200);
  static const Duration mediumAnimation = Duration(milliseconds: 400);
  static const Duration longAnimation = Duration(milliseconds: 600);

  // Storage Keys
  static const String keyAuthToken = 'auth_token';
  static const String keyUserId = 'user_id';
  static const String keyLastSync = 'last_sync';
  static const String keyIsFirstLaunch = 'is_first_launch';
}

class ApiEndpoints {
  static const String login = '/api/collections/users/auth-with-password';
  static const String register = '/api/collections/users/records';
  static const String sync = '/api/v1/sync';
  static const String cycleCreate = '/api/v1/cycle/create';
  static const String cycleFinish = '/api/v1/cycle/finish';
  static const String cycleCurrent = '/api/v1/cycle/current';
  static const String statsHistory = '/api/v1/stats/history';
  static const String statsSummary = '/api/v1/stats/summary';
  static const String profileBodyweight = '/api/v1/profile/bodyweight';
  static const String profileInventory = '/api/v1/profile/inventory';
  static const String userUpdate = '/api/collections/users/records'; // + /:id
  static const String userDelete = '/api/collections/users/records'; // + /:id
  static const String profileReset = '/api/v1/profile/reset';
}

class ExerciseIds {
  static const String squat = 'squat';
  static const String pullup = 'pullup_weighted';
  static const String dip = 'dip_weighted';
}

class ExerciseNames {
  static const String squat = 'Back Squat';
  static const String pullup = 'Weighted Pull-up';
  static const String dip = 'Weighted Dip';
}
