/**
 * Registration Model
 *
 *
 * To seperate all login for Script
 *
 */
import React from 'react';

import Base from '../base/base';

import { ApiUtils } from './../../lib/'


class CoreScript extends Base {

    constructor() {
        super();

        this.fields = [
            {
                field: 'name',
                caption: 'Name'
            },
            {
                field: 'amount',
                caption: 'Amount'
            }
        ];

        // this.columns = ;
    }

    get id() {
        return 'id';
    }

    get getEndpoint() {
        return 'core-scripts';
    }


    get modelName() {
        return `core-scripts`;
    }

    get columns() {
        return [
            {
                caption: 'Staff',
                field: 'staff.name',
                key: 'staff'
            },
            {
                caption: 'Weight',
                field: 'weight',
                key: 'weight'
            },
            {
                caption: 'Date',
                field: 'created_at',
                key: 'created_at'
            }
        ];
    }


    /**
     *Getting core_script data
     * @returns
     */
    getReportingLisitng = (id, formBody) => {
        // console.log('Fb', formBody);

        return ApiUtils.post({
            url: `core-scripts/dashboardquery/${id}`,
            formBody,
        });
    };


    /**
     *Updating user details
     * @returns
     */
    getUserDetailsLisitng = (id, formBody) => {

        return ApiUtils.post({
            url: `core-scripts/update-user-deatils/${id}`,
            formBody,
        });
    };


    /**
     * 
     */
    getReportMenu = async ({ id }) => {

        const result = await this.getRecord({ id });

        const report = result.result

        return {
            ...report,
            caption: report.caption,
            path: '/reports/' + report.id,
            is_visible: true
        }
    }

    /**
      * To get extra script data corresponding to mode
      *
      * @param {*} mode
      * @returns
      */
    getExtraInfo = (mode) => {
        return ApiUtils.get({
            url: `core-scripts/get-script-data?mode=${mode}`,
        });
    };


    /**
      * To get executed data
      *
      * @param {*} mode
      * @returns
      */

    getSelectedExtraInfo = (formBody) => {
        return ApiUtils.post({
            url: `core-scripts/get-selected-script-data`,
            formBody,
            headers: {
                'Content-Type': 'application/json',
                Authorization: 'Bearer ' + localStorage.access_token,
            },
        });
    };
}

export default CoreScript;
