// Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import 'package:example_router/core/enums/dev_mode.dart';
import 'package:flutter/material.dart';

abstract class Flavor {
  Flavor._({
    this.banner,
    this.bannerColor = Colors.red,
    this.devMode,
  }) {
    _instance = this;
  }

  static Flavor? _instance;

  final String? banner;
  final Color bannerColor;
  final DevMode? devMode;

  /// Returns [Flavor] instance.
  static Flavor get() {
    if (_instance == null) {
      throw Exception('Flavor not initialized!');
    }

    return _instance!;
  }

  @override
  String toString() => runtimeType.toString().replaceAll('Flavor', '');
}

class DevelopmentFlavor extends Flavor {
  factory DevelopmentFlavor() {
    const modeString = String.fromEnvironment('dev_mode', defaultValue: 'mock');
    final mode = DevMode.fromString(modeString);

    return DevelopmentFlavor._(devMode: mode);
  }
  DevelopmentFlavor._({
    required super.devMode,
  }) : super._(
          banner: 'Dev',
        );
}

class StagingFlavor extends Flavor {
  StagingFlavor()
      : super._(
          banner: 'Staging',
          bannerColor: Colors.green,
        );
}

class ProductionFlavor extends Flavor {
  ProductionFlavor() : super._();
}
