import 'package:app/request/dto/room/room_list_item_dto.dart';

class MeetingRoomDto {
  int id;
  final String roomName;
  final String startTime;
  final String endTime;
  String actualStartTime;
  int roomStatus;
  String boardUuid;

  MeetingRoomDto({
    required this.id,
    this.roomName = "",
    this.startTime = "",
    this.endTime = "",
    this.actualStartTime = "",
    this.roomStatus = 0,
    this.boardUuid = "",
  });

  /// 根据 RoomListItemDto 创建
  MeetingRoomDto.fromRoomListItem(RoomListItemDto item)
    : id = item.id,
      roomName = item.roomName,
      startTime = item.startTime,
      endTime = item.endTime,
      actualStartTime = "",
      roomStatus = 0,
      boardUuid = "";

  /// 从 JSON 创建对象
  factory MeetingRoomDto.fromJson(Map<String, dynamic> json) {
    return MeetingRoomDto(
      id: json['id'] ?? 0,
      roomName: json['room_name'] as String,
      startTime: json['start_time'] as String,
      endTime: json['end_time'] as String,
      actualStartTime: json['actual_start_time']  ?? "",
      roomStatus: json['room_status'] ?? 0,
      boardUuid: json['board_uuid'] ?? "",
    );
  }

  /// 转为 JSON
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'room_name': roomName,
      'start_time': startTime,
      'end_time': endTime,
      'actual_start_time': actualStartTime,
      'room_status': roomStatus,
      'board_uuid': boardUuid,
    };
  }

  /// 复制对象，可修改部分字段
  MeetingRoomDto copyWith({
    int? id,
    String? roomName,
    String? startTime,
    String? endTime,
    String? actualStartTime,
    int? roomStatus,
    String? boardUuid,
  }) {
    return MeetingRoomDto(
      id: id ?? this.id,
      roomName: roomName ?? this.roomName,
      startTime: startTime ?? this.startTime,
      endTime: endTime ?? this.endTime,
      actualStartTime: actualStartTime ?? this.actualStartTime,
      roomStatus: roomStatus ?? this.roomStatus,
      boardUuid: boardUuid ?? this.boardUuid,
    );
  }
}
