// 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:yaml/yaml.dart';

const _onTrueKey = 'on_true';
const _onFalseKey = 'on_false';

class BooleanFileSystemVariable {
  BooleanFileSystemVariable({
    required this.onTrueNames,
    required this.onFalseNames,
  });

  factory BooleanFileSystemVariable.fromYaml(YamlMap? source) {
    if (source == null) {
      throw ArgumentError.notNull('source');
    }

    final onTrueNames = (source[_onTrueKey] as YamlList?)
        ?.map((element) => element as String)
        .toList();
    final onFalseNames = (source[_onFalseKey] as YamlList?)
        ?.map((element) => element as String)
        .toList();

    return BooleanFileSystemVariable(
      onTrueNames: onTrueNames ?? [],
      onFalseNames: onFalseNames ?? [],
    );
  }

  factory BooleanFileSystemVariable.empty() => BooleanFileSystemVariable(
        onTrueNames: [],
        onFalseNames: [],
      );

  final List<String> onTrueNames;
  final List<String> onFalseNames;

  BooleanFileSystemVariable copyWith({
    List<String>? onTrueNames,
    List<String>? onFalseNames,
  }) =>
      BooleanFileSystemVariable(
        onTrueNames: onTrueNames ?? this.onTrueNames,
        onFalseNames: onFalseNames ?? this.onFalseNames,
      );

  @override
  String toString() => 'BooleanFileSystemVariable(onTrueNames: $onTrueNames, '
      'onFalseNames: $onFalseNames)';
}
