class Phone{

    _sms = {};
    get hasSms(){
        return (this.smsContacts.length > 0);
    }
    
    get sms(){
        return this._sms;
    }

    get smsContacts(){
        //return [...new Set(this._sms.map(sms=>sms.sender).filter(Boolean))];
        return Object.keys(this._sms);
    }

    smsBySender(senderId){
        //return this.sms.filter((sms)=>sms.sender == senderId);
        return this._sms[senderId]?.messages ?? [];
    }

    smsCreate(senderId,time,body,data=null){
        this._sms[senderId] ??= {messages:[]};
        this._sms[senderId].messages.push({
            time: time,
            body: body,
            seed: rand(0,999999),
            data:data
        });
        this._sms[senderId].hasNew = true;
    }

    smsHasNew(senderId){
        return !!this._sms[senderId]?.hasNew;
    }

    smsSetRead(senderId){
        this._sms[senderId].hasNew = false;
    }

	constructor(){}

	_init(phone){
		Object.keys(phone).forEach(function (pn) {
			this[pn] = clone(phone[pn]);
		}, this);

		return this;
	}

	clone = function () {
		return (new setup.Phone())._init(this);
	};

	toJSON = function () {
		var ownData = {};
		Object.keys(this).forEach(function (pn) {
			if(typeof this[pn] !== "function")
				ownData[pn] = clone(this[pn]);
		}, this);
		return JSON.reviveWrapper('(new setup.Phone())._init($ReviveData$)', ownData);
	};
}

setup.Phone = Phone;