<?php

namespace Aura\Forms\Resources;

use Eminiarts\Aura\Resource;

class Submission extends Resource
{
    // public static $customTable = true;

    public static ?string $slug = 'submission';

    public static ?int $sort = 3;

    public static string $type = 'Submission';

    protected $casts = [
        'data' => 'json',
    ];

    protected static $dropdown = 'Forms';

    protected static ?string $group = 'Aura';

    // protected $table = 'submissions';

    protected static bool $title = false;

    // Relationships
    // public function form()
    // {
    //     return $this->belongsTo(Form::class, 'form_id');
    // }

    public static function getFields()
    {
        return [
            [
                'name' => 'Data',
                'type' => 'Eminiarts\\Aura\\Fields\\Text',
                'on_index' => false,
                'validation' => '',
                'conditional_logic' => [],
                'slug' => 'data',
                'language' => 'json',
            ],
            [
                'name' => 'Status',
                'type' => 'Eminiarts\\Aura\\Fields\\Select',
                'validation' => 'required',
                'conditional_logic' => [],
                'slug' => 'status',
                'options' => [
                    [
                        'value' => 'Pending',
                        'key' => 'pending',
                    ],
                    [
                        'value' => 'Completed',
                        'key' => 'completed',
                    ],
                ],
            ],
            [
                'name' => 'Form',
                'type' => 'Eminiarts\\Aura\\Fields\\BelongsTo',
                'resource' => 'Aura\\Forms\\Resources\\Form',
                'validation' => 'required',
                'conditional_logic' => [],
                'slug' => 'form_id',
            ],
            [
                'name' => 'User Agent',
                'type' => 'Eminiarts\\Aura\\Fields\\Text',
                'on_index' => false,
                'validation' => '',
                'conditional_logic' => [],
                'slug' => 'user_agent',
            ],
            [
                'name' => 'IP-Address',
                'type' => 'Eminiarts\\Aura\\Fields\\Text',
                'on_index' => false,
                'validation' => '',
                'conditional_logic' => [],
                'slug' => 'ip',
            ],
            [
                'name' => 'URL',
                'type' => 'Eminiarts\\Aura\\Fields\\Text',
                'on_index' => false,
                'validation' => '',
                'conditional_logic' => [],
                'slug' => 'url',
            ],
        ];
    }

    public function team()
    {
        return $this->belongsTo(Team::class, 'team_id');
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id');
    }
}
