module api_data;
import mir.serde, util: JsonObject;

struct Moderate {
	string user_id;
	@serdeOptional string reason;
}

struct State {
	struct PowerLevels {
		short[string] users;
	}	

	struct ACL {
		@serdeOptional:
		bool allow_ip_literals;
		string[] allow = ["*"];
		string[] deny;
	}

	JsonObject content;
	string event_id;
	string sender;
	string type;
}

struct Encrypted {
	char[] algorithm;
	char[] ciphertext;
	char[] device_id;
	char[] sender_key;
	char[] session_id;
}

struct MSG {
	struct Meta {
		int h, w;
		ulong size;
		string mimetype;
	}

	struct Relates {
		struct EvtBase {
			string event_id;
		}

		@serdeOptional @serdeKeys("m.in_reply_to") EvtBase reply;
	}

	string body;
	@serdeOptional @serdeIgnoreDefault string formatted_body;
	string msgtype = "m.notice";
	@serdeOptional string format = "org.matrix.custom.html";

	@serdeOptional @serdeIgnoreDefault:
	@serdeKeys("m.relates_to") Relates relates;
	string rel_type;
	string url;
	string filename;
	Meta info;
}

struct Sync {
	struct StrippedStateEvent {
		JsonObject content;
		string sender, state_key, type;
	}

	struct Unsigned {
		int age;
		string membership, transaction_id;
	}

	struct Rooms {
		struct Invited {
			struct IS { StrippedStateEvent[] events; }
			IS invite_state;
		}
		struct Joined {
			struct Timeline {
				EventWithoutRoomID[] events;
				@serdeOptional bool limited;
				string prev_batch;
			}

			struct UNC {
				int highlight_count;
				int notification_count;
			}

			@serdeOptional Timeline timeline;
			@serdeOptional UNC unread_notifications;
		}

		@serdeOptional Invited[string] invite;
		@serdeOptional Joined[string] join;
	}

	@serdeOptional Rooms rooms;
	string next_batch;
}

struct EventWithoutRoomID {
	JsonObject content;
	string event_id;
	ulong origin_server_ts;
	@serdeOptional string sender, state_key, type;
	@serdeIgnore string room;
	// Unsigned unsigned;
}