import {uuid4} from '@extollo/lib'
import {allResourceActions, FieldType, Renderer, ResourceAction, ResourceConfiguration} from '../cobalt'

export default {
    resources: [
        {
            key: 'pendingTransaction',
            primaryKey: 'pending_transaction_id',
            source: {
                collection: 'pending_transactions',
            },
            display: {
                field: 'description',
                singular: 'Pending Transaction',
                plural: 'Pending Transactions',
            },
            orderField: 'tx_date',
            orderDirection: 'desc',
            supportedActions: allResourceActions,
            fields: [
                {
                    key: 'account',
                    display: 'Account',
                    type: FieldType.select,
                    required: true,
                    options: [
                        {display: 'Discover Card', value: 'Assets:Current Assets:Discover Credit'},
                        {display: 'Bank MW Checking', value: 'Assets:Current Assets:Bank MW Checking'},
                    ],
                },
                {
                    key: 'description',
                    display: 'Description',
                    type: FieldType.text,
                    required: true,
                },
                {
                    key: 'amount',
                    display: 'Amount',
                    type: FieldType.number,
                    required: true,
                },
                {
                    key: 'tx_date',
                    display: 'Date',
                    type: FieldType.date,
                    renderer: Renderer.date,
                    required: true,
                },
            ],
        },
        {
            key: 'pageView',
            primaryKey: 'page_view_id',
            source: {
                collection: 'page_views',
            },
            display: {
                field: 'endpoint',
                singular: 'Raw Page View',
                plural: 'Raw Page Views',
            },
            orderField: 'visited_at',
            orderDirection: 'desc',
            supportedActions: [ResourceAction.read, ResourceAction.readOne],
            fields: [
                {
                    key: 'visited_at',
                    display: 'Date',
                    type: FieldType.date,
                    renderer: Renderer.datetime,
                },
                {
                    key: 'endpoint',
                    display: 'Route',
                    type: FieldType.text,
                },
                {
                    key: 'ip',
                    display: 'IP Address',
                    type: FieldType.text,
                },
                {
                    key: 'hostname',
                    display: 'Hostname',
                    type: FieldType.text,
                },
                {
                    key: 'method',
                    display: 'Method',
                    type: FieldType.text,
                },
                {
                    key: 'xhr',
                    display: 'XHR?',
                    type: FieldType.bool,
                    renderer: Renderer.bool,
                },
            ],
        },
        {
            key: 'workItem',
            primaryKey: 'work_item_id',
            source: {
                collection: 'work_items',
            },
            display: {
                field: 'name',
                singular: 'Work Item',
                plural: 'Work Items',
            },
            supportedActions: allResourceActions,
            fields: [
                {
                    key: 'name',
                    display: 'Name',
                    type: FieldType.text,
                    required: true,
                },
                {
                    key: 'description',
                    display: 'Description',
                    type: FieldType.html,
                    required: true,
                    renderer: Renderer.html,
                },
                {
                    key: 'start_date',
                    display: 'Start Date',
                    type: FieldType.date,
                    required: true,
                    sort: 'desc',
                    renderer: Renderer.date,
                },
                {
                    key: 'end_date',
                    display: 'End Date',
                    type: FieldType.date,
                    required: false,
                    renderer: Renderer.date,
                }
            ],
        },
        {
            key: 'snippet',
            primaryKey: 'snippet_id',
            source: {
                collection: 'snippets',
            },
            display: {
                field: 'slug',
                singular: 'Snippet',
                plural: 'Snippets',
            },
            supportedActions: allResourceActions,
            fields: [
                {
                    key: 'slug',
                    display: 'Slug',
                    type: FieldType.text,
                    required: true,
                    sort: 'asc',
                },
                {
                    key: 'syntax',
                    display: 'Syntax',
                    type: FieldType.text,
                    required: true,
                },
                {
                    key: 'users_only',
                    display: 'Users only?',
                    type: FieldType.bool,
                    required: true,
                    renderer: Renderer.bool,
                },
                {
                    key: 'single_access_only',
                    display: 'Single-access only?',
                    type: FieldType.bool,
                    required: true,
                    renderer: Renderer.bool,
                },
                {
                    key: 'access_key',
                    display: 'Access key',
                    type: FieldType.text,
                    required: false,
                    hideOn: {
                        listing: true,
                    },
                },
                {
                    key: 'body',
                    display: 'Content',
                    type: FieldType.textarea,
                    required: true,
                    hideOn: {
                        listing: true,
                    },
                },
            ],
        },
        {
            key: 'contactSubmission',
            primaryKey: 'contact_submission_id',
            source: {
                collection: 'contact_submissions',
            },
            display: {
                field: 'name',
                singular: 'Contact Submission',
                plural: 'Contact Submissions',
            },
            supportedActions: [
                ResourceAction.read, ResourceAction.readOne, ResourceAction.delete,
            ],
            fields: [
                {
                    key: 'name',
                    display: 'Name',
                    type: FieldType.text,
                    required: true,
                },
                {
                    key: 'email',
                    display: 'E-Mail Address',
                    type: FieldType.text,
                    required: true,
                },
                {
                    key: 'message',
                    display: 'Message',
                    type: FieldType.textarea,
                    required: true,
                },
                {
                    key: 'sent_at',
                    display: 'Sent At',
                    type: FieldType.date,
                    renderer: FieldType.date,
                    required: false,
                    sort: 'desc',
                },
            ],
        },
        {
            key: 'goLink',
            primaryKey: 'go_link_id',
            source: {
                collection: 'go_links',
            },
            display: {
                field: 'short',
                singular: 'Go Link',
                plural: 'Go Links',
            },
            supportedActions: allResourceActions,
            fields: [
                {
                    key: 'short',
                    display: 'Slug',
                    type: FieldType.text,
                    required: true,
                    sort: 'asc',
                },
                {
                    key: 'url',
                    display: 'URL',
                    type: FieldType.text,
                    required: true,
                },
                {
                    key: 'active',
                    display: 'Active?',
                    type: FieldType.bool,
                    renderer: Renderer.bool,
                    required: true,
                },
            ],
        },
        {
            key: 'feedPost',
            primaryKey: 'feed_post_id',
            generateKeyOnInsert: uuid4,
            source: {
                collection: 'feed_posts',
            },
            display: {
                // field: '',
                singular: 'Feed Post',
                plural: 'Feed Posts',
            },
            supportedActions: allResourceActions,
            fields: [
                {
                    key: 'posted_at',
                    display: 'Posted At',
                    type: FieldType.date,
                    sort: 'desc',
                    required: false,
                    renderer: Renderer.date,
                },
                {
                    key: 'tag',
                    display: 'Tag',
                    type: FieldType.text,
                    required: true,
                },
                {
                    key: 'body',
                    display: 'Body',
                    type: FieldType.html,
                    renderer: Renderer.html,
                    required: true,
                },
                {
                    key: 'visible',
                    display: 'Visible?',
                    type: FieldType.bool,
                    renderer: Renderer.bool,
                    required: false,
                },
            ],
        }
    ] as ResourceConfiguration[],
}
