import { observable, action, computed } from 'mobx';

export default class PackagePaymentMethod {
	@observable packagePaymentMethodList = [];
	@observable packagePaymentMethodData = {
		id : '',
		package_id : '',
		payment_method_id : '',
	};
	@observable packagePaymentMethodId = '';
	@observable isLoading = false;

	constructor(context) {
	    this.http = context.http;
	    this.context = context;
	}

	@action
	getPackagePaymentMethodByPackageId(id){
		this.isLoading = true;
		this.http.get(`package_payment_methods?package_id=${id}`).then(res => {
			this.packagePaymentMethodList = res;
			this.isLoading = false;
			// console.log(this.contactId);
		});
	}

	@action
	getPackagePaymentMethodById(id){
		this.isLoading = true;
		this.packagePaymentMethodId = id;
		return this.http.get(`package_payment_methods/${id}`).then(res => {
			this.packagePaymentMethodData = res[0];
			this.isLoading = false;
			// console.log(this.contactId);
		});
	}

	// @action
	// getPaymentMethod(){
	// 	this.isLoading = true;
	// 	this.http.get('payment_methods').then(res => {
	// 		this.paymentMethod = res;
	// 		this.isLoading = false;
	// 	});
	// }

	@computed
	get isPackagePaymentMethodEmpty() {
		if(this.packagePaymentMethodList.length > 0) {
			return false;
		}
		return true;
	}

	@action
	postPackagePaymentMethod(package_payment_method_id){
		this.isLoading = true;
		this.http.post(`package_payment_methods`, this.packagePaymentMethodData).then(res => {
			this.isLoading = false;
			this.getPackagePaymentMethodByPackageId(package_payment_method_id);
		});
	}

	@action
	putPackagePaymentMethod(id, package_payment_method_id){
		this.isLoading = true;
		this.http.put(`package_payment_methods/${id}`, this.packagePaymentMethodData).then(res => {
			this.isLoading = false;
			this.getPackagePaymentMethodByPackageId(package_payment_method_id);
			console.log(res);
		});
	}

	@action
	delPackagePaymentMethod(id,package_payment_method_id){
		this.packagePaymentMethodId = id;
		this.isLoading = true;
		this.http.delete(`package_payment_methods/${id}`).then(res => {
			this.isLoading = false;
			// console.log(detail[0]);
			this.getPackagePaymentMethodByPackageId(package_payment_method_id);
			return res;
		})
	}
}	