import CRUDBase from '../CRUDBase.js'
import { session } from '../../service/Session.service.js'

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

        this.endpoint = '/api/v1/auth/users'
        this.required_fields = ['uid', 'first_name', 'last_name', 'email']
        this.permission_base = 'v1:auth:users'

        this.item = 'User'
        this.plural = 'Users'

        this.listing_definition = {
            display: `
        Users can be assigned permissions and, if granted, can manage their ${session.get('app.name')} accounts from the Profile page, as well as login to the external applications they've been given access to.
        `,
            columns: [
                {
                    name: 'UID',
                    field: 'uid',
                },
                {
                    name: 'Last Name',
                    field: 'last_name',
                },
                {
                    name: 'First Name',
                    field: 'first_name',
                },
                {
                    name: 'E-Mail',
                    field: 'email',
                },
            ],
            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 = {
            fields: [
                {
                    name: 'First Name',
                    field: 'first_name',
                    placeholder: 'John',
                    required: true,
                    type: 'text',
                },
                {
                    name: 'Last Name',
                    field: 'last_name',
                    placeholder: 'Doe',
                    required: true,
                    type: 'text',
                },
                {
                    name: 'Username',
                    field: 'uid',
                    placeholder: 'john.doe',
                    required: true,
                    type: 'text',
                },
                {
                    name: 'E-Mail',
                    field: 'email',
                    placeholder: 'john@contoso.com',
                    required: true,
                    type: 'text',
                },
                {
                    name: 'Tagline',
                    field: 'tagline',
                    type: 'text',
                },
                {
                    name: 'Password',
                    field: 'password',
                    type: 'password',
                    placeholder: 'Password',
                    required: ['insert'],
                },
                {
                    name: 'Trap',
                    field: 'trap',
                    type: 'select.dynamic',
                    options: {
                        resource: 'auth/Trap',
                        display: 'name',
                        value: 'trap',
                    },
                },
            ],
        }
    }
}

const auth_user = new UserResource()
export { auth_user }
