import {Channel} from "./channel.js"

class Channels {
	constructor(client) {
		this.client = client;
		this.channel = undefined;
	}

	async createChannel(members_id, reload) {
		
		let response = await this.client._post("/api/chat/", {
			members_id:members_id
		});

		if (response.status >= 300)
			return undefined;

		let data = await response.json();

		let messages = undefined;
		if (response.status == 200)
			messages = data.messages;
		
		this.channel = new Channel(this.client, data.channel_id, members_id, messages, reload);
		return this.channel;
	}

	async deleteChannel(members_id) {
		let response = await this.client._delete("/api/chat/", {
			members_id:members_id
		});

		let data = await response.json();
		console.log(response.status)
		return data;
	}

}

export {Channels}
