<?php

namespace App\Filament\Resources\LoanApplications\Schemas;

use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Textarea;
use Filament\Schemas\Schema;

class LoanApplicationForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Select::make('user_id')
                    ->relationship('user', 'email')
                    ->searchable()
                    ->required(),
                Select::make('collateral_asset_id')
                    ->relationship('collateralAsset', 'symbol')
                    ->searchable()
                    ->required(),
                Select::make('loan_duration_id')
                    ->relationship('loanDuration', 'name')
                    ->searchable()
                    ->required(),
                TextInput::make('loan_amount_usd')
                    ->required()
                    ->numeric(),
                TextInput::make('required_collateral_coin')
                    ->required()
                    ->numeric(),
                TextInput::make('wallet_provider_name'),
                TextInput::make('network'),
                TextInput::make('wallet_address'),
                TextInput::make('expected_collateral_usd')
                    ->numeric(),
                FileUpload::make('kyc_id_document_path')
                    ->disk('public')
                    ->directory('uploads/kyc')
                    ->downloadable()
                    ->openable()
                    ->previewable(),
                FileUpload::make('kyc_selfie_path')
                    ->disk('public')
                    ->directory('uploads/kyc')
                    ->downloadable()
                    ->openable()
                    ->previewable(),
                FileUpload::make('payment_proof_path')
                    ->disk('public')
                    ->directory('uploads/payment-proofs')
                    ->downloadable()
                    ->openable()
                    ->previewable(),
                Select::make('status')
                    ->required()
                    ->default('awaiting_collateral_payment'),
                Textarea::make('metadata')
                    ->columnSpanFull(),
                DateTimePicker::make('submitted_at'),
                DateTimePicker::make('payment_proof_submitted_at'),
            ]);
    }
}
