/// 程序模型
class Program {
  final int? id;
  final String code;
  final String name;
  final String createdAt;
  final int status; // 1: 启用, 0: 停用
  final int temperature;
  final int airflowTime;

  Program({
    this.id,
    required this.code,
    required this.name,
    required this.createdAt,
    this.status = 1,
    this.temperature = 50,
    this.airflowTime = 60,
  });

  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'code': code,
      'name': name,
      'created_at': createdAt,
      'status': status,
      'temperature': temperature,
      'airflow_time': airflowTime,
    };
  }

  factory Program.fromMap(Map<String, dynamic> map) {
    return Program(
      id: map['id'] as int?,
      code: map['code'] as String,
      name: map['name'] as String,
      createdAt: map['created_at'] as String,
      status: map['status'] as int? ?? 1,
      temperature: map['temperature'] as int? ?? 50,
      airflowTime: map['airflow_time'] as int? ?? 60,
    );
  }

  Program copyWith({
    int? id,
    String? code,
    String? name,
    String? createdAt,
    int? status,
    int? temperature,
    int? airflowTime,
  }) {
    return Program(
      id: id ?? this.id,
      code: code ?? this.code,
      name: name ?? this.name,
      createdAt: createdAt ?? this.createdAt,
      status: status ?? this.status,
      temperature: temperature ?? this.temperature,
      airflowTime: airflowTime ?? this.airflowTime,
    );
  }
}
