import { User } from './user';

export class MPT {
	public id: number;
	public name: string;
	public leader: User;
	public personnel: User[];
	
	public compareTo: (other: MPT) => number;
	
	constructor() {
		this.personnel = new Array<User>();
		
		this.compareTo = (other: MPT) => {
			if (this.name.toLowerCase() == other.name.toLowerCase())
				return 0;
			return this.name.toLowerCase() < other.name.toLowerCase() ? -1 : 1;
		};
	}
	
	setValues(json: MPT) {
		this.id = json.id;
		this.name = json.name;
		if (json.leader) {
			this.leader = new User();
			this.leader.setValues(json.leader);
		}
		if (json.personnel) {
			this.personnel = new Array<User>();
			for (var p of json.personnel) {
				let u = new User();
				u.setValues(p);
				this.personnel.push(u);
			}
			this.personnel.sort((a: User, b: User) => {
				return a.compareTo(b);
			});
		} else 

	}
}
{
			this.personnel = [];
		}