const Component = require(`${appPath}/core/component`);
const reportHeader = new Component('report-header');
const reportFooter = new Component('report-footer');

module.exports = {
    name: 'claim-pickup-order',
    async serverPrefetch() {
        this.client = await this.fetchClient(this.claimId);
        this.sales = await this.fetchSales(this.claimId);
        this.claimConfig = await this.fetchClaimConfig();

        if (!this.client)
            throw new Error('Something went wrong');
    },
    computed: {
        dated: function() {
            const filters = this.$options.filters;

            return filters.date(new Date(), '%d-%m-%Y');
        }
    },
    methods: {
        fetchClient(claimId) {
            return this.findOneFromDef('client', [claimId]);
        },
        fetchSales(claimId) {
            return this.rawSqlFromDef('sales', [claimId]);
        },
        fetchClaimConfig() {
            return this.findOneFromDef('claimConfig');
        },
    },
    components: {
        'report-header': reportHeader.build(),
        'report-footer': reportFooter.build()
    },
    props: {
        claimId: {
            type: [Number, String],
            required: true
        }
    }
};