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

export default class Bank {
    
        @observable list = [];
        @observable listAdmin = [];
        @observable isLoading = false;
        @observable data = {
            name : '',
            currency_id: '',
            account_number : '',
            on_behalf : '',
            id: '',
        };
    
        constructor(context) {
            this.http = context.http;
            this.context = context;
        }
    
    
        @action
        getAll(){
            this.isLoading = true;
            return this.http.get(`user_banks?user_id=hai`).then(res => {
                this.isLoading = false;
                this.list = res;
            });
        }

        @action
        getAdminBank(){
            this.isLoading = true;
            return this.http.get(`dsm_bank`).then(res => {
                this.isLoading = false;
                this.listAdmin = res;
            });
        }

        @action
        getByUserID(id){
            this.isLoading = true;
            return this.http.get(`user_banks?user_id=${id}`).then(res => {
                this.isLoading = false;
                this.list = res;
            });
        }
    
        @computed
        get isEmpty() {
            if(this.list.length > 0) {
                return false;
            }
            return true;
        }  
        
        @action
        post(){
            this.isLoading = true;
            this.http.post('user_banks', this.data).then(res => {
                this.isLoading = false;
                this.getByUserID();
                return res;
            })
        }
    }