import ChatMessage from "../model/ChatMessage";
import SimpleChatView from "../widget/SimpleChatView";
import ChatRoomAdapter from "./adapter/ChatRoomAdapter";
import FriendListAdapter from "./adapter/FriendListAdapter";
import SimpleChatAdapter from "./adapter/SimpleChatAdapter";
import VideosAdapter from "./adapter/VideosAdapter";
import ChatRoomRecyclerData from "./data/ChatRoomRecyclerData";
import FriendListRecyclerData from "./data/FriendListRecyclerData";
import FriendListFragment from "./fragment/FriendListFragment";
import RoomListFragment from "./fragment/RoomListFragment";
import FriendListXmL from "./layout/FriendListXmL";
import ReceiveImageMessageItemXML from "./layout/ReceiveImageMessageItemXML";
import ReceiveTextMessageItemXML from "./layout/ReceiveTextMessageItemXML";
import ReceiveVideoMessageItemXML from "./layout/ReceiveVideoMessageItemXML";
import RoomDataXML from "./layout/RoomDataXML";
import RoomListXML from "./layout/RoomListXML";
import SendImageMessageItemXML from "./layout/SendImageMessageItemXML";
import SendTextMessageItemXML from "./layout/SendTextMessageItemXML";
import SendVideoMessageItemXML from "./layout/SendVideoMessageItemXML";
import SimpleChatViewWidgetXML from "./layout/SimpleChatViewWidgetXML";
import ItemBroadcastVideoXML from "./layout/ItemBroadcastVideoXML";
import UserData from "./layout/UserData";
import ChatRequestModel from "./model/ChatRequestModel";
import ChatResponseModel from "./model/ChatResponseModel";
import ChatRoomResnponseModel from "./model/ChatRoomResnponseModel";
import CreateRoomRequests from "./model/CreateRoomRequests";
import FriendListResponse from "./model/FriendListResponse";
import GetVideoListResponse from "./model/GetVideoListResponse";

export function findComponents(data, result = []) {
  if (!Array.isArray(data)) data = [data];
  for (const item of data) {
    if ("components" in item) {
      findComponents(item.components, result);
    }
    if ("children" in item) {
      findComponents(item.children, result);
    }
    if ("props" in item && item.name == "ChatUi") {
      result.push(item);
    }
  }
  return result;
}

export const generateOtherUI = (configuration) => {
  let copyList = [];

  // .........CHATUI COMPONENTS  STARTS...............
  const chatComp = (configuration) => {
    if (findComponents(configuration.fragment).length == 0) {
      return "";
    } else {
      //Data
      copyList.push({
        fileName:
          "app/src/main/java/com/" +
          configuration.name.toLowerCase() +
          "/app/data/ChatRoomRecyclerData.kt",
        content: ChatRoomRecyclerData(configuration),
      });
      copyList.push({
        fileName:
          "app/src/main/java/com/" +
          configuration.name.toLowerCase() +
          "/app/data/FriendListRecyclerData.kt",
        content: FriendListRecyclerData(configuration),
      });
      //Adapters
      copyList.push({
        fileName:
          "app/src/main/java/com/" +
          configuration.name.toLowerCase() +
          "/app/adapters/ChatRoomAdapter.kt",
        content: ChatRoomAdapter(configuration),
      });
      copyList.push({
        fileName:
          "app/src/main/java/com/" +
          configuration.name.toLowerCase() +
          "/app/adapters/FriendListAdapter.kt",
        content: FriendListAdapter(configuration),
      });

      // UI
      // Fragments;
      copyList.push({
        fileName:
          "app/src/main/java/com/" +
          configuration.name.toLowerCase() +
          "/app/ui/fragments/chatui/FriendListFragment.kt",
        content: FriendListFragment(configuration),
      });
      copyList.push({
        fileName:
          "app/src/main/java/com/" +
          configuration.name.toLowerCase() +
          "/app/ui/fragments/chatui/RoomListFragment.kt",
        content: RoomListFragment(configuration),
      });

      // .........CHATUI COMPONENTS  ENDS...............
    }
  };
  chatComp(configuration);

  // Models needs to be exported for the apiserve and apirepository
  // Model
  copyList.push({
    fileName:
      "app/src/main/java/com/" +
      configuration.name.toLowerCase() +
      "/app/model/remote/" +
      "ChatMessage.kt",
    content: ChatMessage(configuration),
  });
  copyList.push({
    fileName:
      "app/src/main/java/com/" +
      configuration.name.toLowerCase() +
      "/app/model/remote/ChatRequest.kt",
    content: ChatRequestModel(configuration),
  });
  copyList.push({
    fileName:
      "app/src/main/java/com/" +
      configuration.name.toLowerCase() +
      "/app/model/remote/ChatResponse.kt",
    content: ChatResponseModel(configuration),
  });
  copyList.push({
    fileName:
      "app/src/main/java/com/" +
      configuration.name.toLowerCase() +
      "/app/model/remote/ChatRoomResponse.kt",
    content: ChatRoomResnponseModel(configuration),
  });
  copyList.push({
    fileName:
      "app/src/main/java/com/" +
      configuration.name.toLowerCase() +
      "/app/model/remote/FriendListResponse.kt",
    content: FriendListResponse(configuration),
  });
  copyList.push({
    fileName:
      "app/src/main/java/com/" +
      configuration.name.toLowerCase() +
      "/app/model/remote/GetVideoListResponse.kt",
    content: GetVideoListResponse(configuration),
  });
  copyList.push({
    fileName:
      "app/src/main/java/com/" +
      configuration.name.toLowerCase() +
      "/app/model/remote/CreateRoomRequests.kt",
    content: CreateRoomRequests(configuration),
  });

  //widget
  copyList.push({
    fileName:
      "app/src/main/java/com/" +
      configuration.name.toLowerCase() +
      "/app/widget/SimpleChatView.kt",
    content: SimpleChatView(configuration),
  });

  //Layouts

  copyList.push({
    fileName: "app/src/main/res/layout/simple_chat_view_widget.xml",
    content: SimpleChatViewWidgetXML(configuration),
  });
  copyList.push({
    fileName: "app/src/main/res/layout/send_video_message_item.xml",
    content: SendVideoMessageItemXML(configuration),
  });
  copyList.push({
    fileName: "app/src/main/res/layout/send_text_message_item.xml",
    content: SendTextMessageItemXML(configuration),
  });
  copyList.push({
    fileName: "app/src/main/res/layout/send_image_message_item.xml",
    content: SendImageMessageItemXML(configuration),
  });
  copyList.push({
    fileName: "app/src/main/res/layout/receive_video_message_item.xml",
    content: ReceiveVideoMessageItemXML(configuration),
  });
  copyList.push({
    fileName: "app/src/main/res/layout/receive_text_message_item.xml",
    content: ReceiveTextMessageItemXML(configuration),
  });
  copyList.push({
    fileName: "app/src/main/res/layout/receive_image_message_item.xml",
    content: ReceiveImageMessageItemXML(configuration),
  });
  copyList.push({
    fileName: "app/src/main/res/layout/room_data.xml",
    content: RoomDataXML(configuration),
  });
  copyList.push({
    fileName: "app/src/main/res/layout/fragment_room_list.xml",
    content: RoomListXML(configuration),
  });
  copyList.push({
    fileName: "app/src/main/res/layout/user_data.xml",
    content: UserData(configuration),
  });
  copyList.push({
    fileName: "app/src/main/res/layout/fragment_friend_list.xml",
    content: FriendListXmL(configuration),
  });
  copyList.push({
    fileName: "app/src/main/res/layout/item_broadcast_video.xml",
    content: ItemBroadcastVideoXML(configuration),
  });

  // Ui Adapters
  copyList.push({
    fileName:
      "app/src/main/java/com/" +
      configuration.name.toLowerCase() +
      "/app/ui/adapter/SimpleChatAdapter.kt",
    content: SimpleChatAdapter(configuration),
  });

  //Adapters
  copyList.push({
    fileName:
      "app/src/main/java/com/" +
      configuration.name.toLowerCase() +
      "/app/adapters/VideosAdapter.kt",
    content: VideosAdapter(configuration),
  });

  return copyList;
};
