// ignore_for_file: non_constant_identifier_names, avoid_init_to_null

import 'package:json_annotation/json_annotation.dart';
import 'package:oto/oto/commands/command.dart';
import 'package:oto/oto/data/pipeline_data.dart';

// Domain data exports — import this file to access all command data classes
export 'base_data.dart';
export 'build_data.dart';
export 'file_data.dart';
export 'git_data.dart';
export 'infra_data.dart';
export 'integration_data.dart';
export 'network_data.dart';
export 'notification_data.dart';
export 'util_data.dart';

part 'command_data.g.dart';

/// ***************************** Base Data ****************************///
@JsonSerializable()
class DataBuild {
  late DataScheduler? scheduler;
  late Map<String, dynamic>? property;
  late DataPipeline? pipeline;
  late List<DataCommand> commands;

  DataBuild();

  factory DataBuild.fromJson(Map<String, dynamic> json) =>
      _$DataBuildFromJson(json);
  Map<String, dynamic> toJson() => _$DataBuildToJson(this);
}

@JsonSerializable()
class DataScheduler {
  late String alias;
  late String? cron;
  late int? interval;
  late bool? enableLog;

  DataScheduler();

  factory DataScheduler.fromJson(Map<String, dynamic> json) =>
      _$DataSchedulerFromJson(json);
  Map<String, dynamic> toJson() => _$DataSchedulerToJson(this);
}

@JsonSerializable()
class DataCommand {
  DataCommand();

  late CommandType command;
  late String id;
  late dynamic param;

  String get name {
    return command.toString().replaceAll('CommandType.', '');
  }

  factory DataCommand.fromJson(Map<String, dynamic> json) =>
      _$DataCommandFromJson(json);
  Map<String, dynamic> toJson() => _$DataCommandToJson(this);
}
