
// @ts-nocheck
import React from 'react';
import Base from './base/base';

class ModelColumns extends Base {

    constructor() {
        super();

        this.fields = [
            {
                field: 'name',
                caption: 'Name',
            },

            {
                field: 'description',
                caption: 'Description',
            },

            {
                field: 'path',
                caption: 'Path',
            },
        ];
    }

    get getEndpoint() {
        return 'modelcolumns';
    }

    get path() {
        return `modelcolumns`;
    }

    get getName() {
        return this.modelName + `s`;
    }

    get modelName() {
        return `modelcolumn`;
    }

    get route() {
        return 'modelcolumns';
    }

    get link() {
        return 'modelcolumns'
    }

    /**
     *
     */
    get columns() {
        return [
            {
                caption: 'Type',
                field: 'type',
                key: 'type',
            },

            {
                caption: 'Description',
                field: 'description',
                key: 'description',
            },

            {
                caption: 'Mode',
                field: 'mode',
                key: 'mode',
            },

            {
                caption: 'Created By',
                field: 'created_by',
                key: 'created_by',
            },

            {
                caption: 'Created at',
                field: 'created_at',
                key: 'created_at',
            },
        ];
    }

    getFormColumns = (id) => {

        let config = {
            queries: [{
                field: '"Modelcolumns".model_id',
                value: id
            }],
            includes: 'column,column.column_type'
        }

        return this.get(config).then((result) => {

            var response = result.map((field) => {

                return {
                    field: field.column.name,
                    label: field.column.display_name,
                    type: field.column.column_type.name,
                    required: field.column.required
                }

            })

            return response;

        })
    }


}

export default ModelColumns;
