// 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:brick_generator/models/brick_variable.dart';
import 'package:brick_generator/models/variable_type.dart';
import 'package:yaml/yaml.dart';

const _typeKey = 'type';
const _descriptionKey = 'description';
const _defaultKey = 'default';
const _promptKey = 'prompt';

class BrickVariableBoolean extends BrickVariable<bool> {
  BrickVariableBoolean({
    required super.type,
    required super.name,
    required super.description,
    required super.defaultValue,
    required super.prompt,
  });

  factory BrickVariableBoolean.fromYaml(String key, YamlMap? source) {
    if (source == null) {
      throw ArgumentError.notNull('source');
    }

    final type = VariableType.fromString(source[_typeKey] as String?);

    return BrickVariableBoolean(
      type: type,
      name: key,
      description: source[_descriptionKey] as String? ?? '',
      defaultValue: source[_defaultKey] as bool? ?? false,
      prompt: source[_promptKey] as String? ?? '',
    );
  }

  @override
  String toString() => 'BrickVariableBoolean(name: $name, '
      'description: $description, defaultValue: $defaultValue, '
      'prompt: $prompt,)';
}
