import CRUDBase from '../CRUDBase.js'

class MachineResource extends CRUDBase {
    constructor() {
        super()

        this.endpoint = '/api/v1/ldap/machines'
        this.required_fields = ['name', 'description']
        this.permission_base = 'v1:ldap:machines'

        this.item = 'Computer'
        this.plural = 'Computers'

        this.listing_definition = {
            columns: [
                {
                    name: 'Machine Name',
                    field: 'name',
                },
                {
                    name: 'Host Name',
                    field: 'host_name',
                },
                {
                    name: 'Description',
                    field: 'description',
                },
            ],
            actions: [
                {
                    type: 'resource',
                    position: 'main',
                    action: 'insert',
                    text: 'Create New',
                    color: 'success',
                },
                {
                    type: 'resource',
                    position: 'row',
                    action: 'update',
                    icon: 'fa fa-edit',
                    color: 'primary',
                },
                {
                    type: 'resource',
                    position: 'row',
                    action: 'delete',
                    icon: 'fa fa-times',
                    color: 'danger',
                    confirm: true,
                },
            ],
        }

        this.form_definition = {
            // back_action: {
            //    text: 'Back',
            //    action: 'back',
            // },
            fields: [
                {
                    name: 'Machine Name',
                    field: 'name',
                    placeholder: 'DNS01',
                    required: true,
                    type: 'text',
                },
                {
                    name: 'Description',
                    field: 'description',
                    required: true,
                    type: 'textarea',
                },
                {
                    name: 'Location',
                    field: 'location',
                    type: 'text',
                    placeholder: 'Server room 1',
                },
                {
                    name: 'Host Name (FQDN)',
                    field: 'host_name',
                    type: 'text',
                    placeholder: 'dns01.my.domain',
                },
                {
                    name: 'IAM Target',
                    field: 'id',
                    type: 'text',
                    readonly: true,
                    hidden: ['insert'],
                    help: `(LDAP use) Allows restricting users to only those that can access this computer. (filter: iamTarget)`,
                },
                {
                    name: 'IAM Filter',
                    field: 'iam_filter',
                    type: 'text',
                    readonly: true,
                    hidden: ['insert'],
                    help: `(LDAP use) Use this filter to restrict access to only users granted IAM access to this computer.`,
                },
            ],
        }
    }
}

const ldap_machine = new MachineResource()
export { ldap_machine }
