class OneTimeTaskData {
  int? id;
  int? oneTimeSettingId;
  OneTimeSetting? oneTimeSetting;
  String? userId;
  String? userName;
  int? siteId;
  String? siteName;
  int? buildingId;
  String? buildingName;
  int? floorId;
  String? floorName;
  int? departmentID;
  String? departmentName;
  int? roomId;
  String? roomName;
  String? locationDescription;
  String? startTime;
  String? endTime;
  int? statusId;
  String? statusName;
  int? statusValue;
  List<Instruction>? instructions;
  List<Attachment>? attachments;
  String? createdDate;
  String? createdBy;
  String? imageRoom; // For backward compatibility - deprecated
  List<String>? imageRooms; // For multiple captured images (max 2)

  OneTimeTaskData({
    this.id,
    this.oneTimeSettingId,
    this.oneTimeSetting,
    this.userId,
    this.userName,
    this.siteId,
    this.siteName,
    this.buildingId,
    this.buildingName,
    this.floorId,
    this.floorName,
    this.departmentID,
    this.departmentName,
    this.roomId,
    this.roomName,
    this.locationDescription,
    this.startTime,
    this.endTime,
    this.statusId,
    this.statusName,
    this.statusValue,
    this.instructions,
    this.attachments,
    this.createdDate,
    this.createdBy,
    this.imageRoom,
    this.imageRooms,
  });

  factory OneTimeTaskData.fromJson(Map<String, dynamic> json) {
    return OneTimeTaskData(
      id: json['id'],
      oneTimeSettingId: json['oneTimeSettingId'],
      oneTimeSetting: json['oneTimeSetting'] != null ? OneTimeSetting.fromJson(json['oneTimeSetting']) : null,
      userId: json['userId'],
      userName: json['userName'],
      siteId: json['siteId'],
      siteName: json['siteName'],
      buildingId: json['buildingId'],
      buildingName: json['buildingName'],
      floorId: json['floorId'],
      floorName: json['floorName'],
      departmentID: json['departmentID'],
      departmentName: json['departmentName'],
      roomId: json['roomId'],
      roomName: json['roomName'],
      locationDescription: json['locationDescription'],
      startTime: json['startTime'],
      endTime: json['endTime'],
      statusId: json['statusId'],
      statusName: json['statusName'],
      statusValue: json['statusValue'],
      instructions: json['instructions'] != null
          ? (json['instructions'] as List).map((i) => Instruction.fromJson(i)).toList()
          : null,
      attachments: json['attachments'] != null
          ? (json['attachments'] as List).map((a) => Attachment.fromJson(a)).toList()
          : null,
      createdDate: json['createdDate'],
      createdBy: json['createdBy'],
      imageRoom: json['imageRoom'],
      imageRooms: json['imageRooms'] != null ? List<String>.from(json['imageRooms']) : null,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'oneTimeSettingId': oneTimeSettingId,
      'oneTimeSetting': oneTimeSetting?.toJson(),
      'userId': userId,
      'userName': userName,
      'siteId': siteId,
      'siteName': siteName,
      'buildingId': buildingId,
      'buildingName': buildingName,
      'floorId': floorId,
      'floorName': floorName,
      'departmentID': departmentID,
      'departmentName': departmentName,
      'roomId': roomId,
      'roomName': roomName,
      'locationDescription': locationDescription,
      'startTime': startTime,
      'endTime': endTime,
      'statusId': statusId,
      'statusName': statusName,
      'statusValue': statusValue,
      'instructions': instructions?.map((i) => i.toJson()).toList(),
      'attachments': attachments?.map((a) => a.toJson()).toList(),
      'createdDate': createdDate,
      'createdBy': createdBy,
      'imageRoom': imageRoom,
      'imageRooms': imageRooms,
    };
  }
}

class OneTimeSetting {
  int? id;
  int? taskTypeId;
  String? taskTypeName;
  int? instructionDescriptionId;
  String? instructionDescriptionName;
  int? sla;

  OneTimeSetting({
    this.id,
    this.taskTypeId,
    this.taskTypeName,
    this.instructionDescriptionId,
    this.instructionDescriptionName,
    this.sla,
  });

  factory OneTimeSetting.fromJson(Map<String, dynamic> json) {
    return OneTimeSetting(
      id: json['id'],
      taskTypeId: json['taskTypeId'],
      taskTypeName: json['taskTypeName'],
      instructionDescriptionId: json['instructionDescriptionId'],
      instructionDescriptionName: json['instructionDescriptionName'],
      sla: json['sla'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'taskTypeId': taskTypeId,
      'taskTypeName': taskTypeName,
      'instructionDescriptionId': instructionDescriptionId,
      'instructionDescriptionName': instructionDescriptionName,
      'sla': sla,
    };
  }
}

class Instruction {
  int? id;
  int? instructionTextId;
  String? instructionText;
  bool? isRequired;
  bool? isDone;
  String? comment;

  Instruction({
    this.id,
    this.instructionTextId,
    this.instructionText,
    this.isRequired,
    this.isDone,
    this.comment,
  });

  factory Instruction.fromJson(Map<String, dynamic> json) {
    return Instruction(
      id: json['id'],
      instructionTextId: json['instructionTextId'],
      instructionText: json['instructionText'],
      isRequired: json['isRequired'],
      isDone: json['isDone'],
      comment: json['comment'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'instructionTextId': instructionTextId,
      'instructionText': instructionText,
      'isRequired': isRequired,
      'isDone': isDone,
      'comment': comment,
    };
  }
}

class Attachment {
  int? id;
  String? name;
  String? originalName;
  String? fileName; // For backward compatibility
  String? fileUrl; // For backward compatibility
  String? fileType;

  Attachment({
    this.id,
    this.name,
    this.originalName,
    this.fileName,
    this.fileUrl,
    this.fileType,
  });

  factory Attachment.fromJson(Map<String, dynamic> json) {
    return Attachment(
      id: json['id'],
      name: json['name'],
      originalName: json['originalName'],
      fileName: json['fileName'],
      fileUrl: json['fileUrl'],
      fileType: json['fileType'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'originalName': originalName,
      'fileName': fileName,
      'fileUrl': fileUrl,
      'fileType': fileType,
    };
  }
}
