import ngModule from '../module';
import ModuleCard from 'salix/components/module-card';

class Controller extends ModuleCard {
    reload() {
        let filter = {
            include: [
                {
                    relation: 'worker',
                    scope: {
                        fields: ['userFk'],
                        include: {
                            relation: 'user',
                            scope: {
                                fields: ['name']
                            }
                        }
                    }
                }, {
                    relation: 'ticket',
                    scope: {
                        fields: ['zoneFk', 'addressFk'],
                        include: [
                            {
                                relation: 'zone',
                                scope: {
                                    fields: ['name']
                                }
                            },
                            {
                                relation: 'address',
                                scope: {
                                    fields: ['provinceFk'],
                                    include: {
                                        relation: 'province',
                                        scope: {
                                            fields: ['name']
                                        }
                                    }
                                }
                            }]
                    }
                }, {
                    relation: 'claimState',
                    scope: {
                        fields: ['id', 'description']
                    }
                }, {
                    relation: 'client',
                    scope: {
                        fields: ['salesPersonFk', 'name', 'email'],
                        include: {
                            relation: 'salesPersonUser'
                        }
                    }
                }
            ]
        };

        this.$http.get(`Claims/${this.$params.id}`, {filter})
            .then(res => this.claim = res.data);
    }
}

ngModule.vnComponent('vnClaimCard', {
    template: require('./index.html'),
    controller: Controller
});