<?php

namespace App\Filament\Resources\Contracts;

use App\Filament\Resources\Contracts\Pages;
use App\Models\Contract;
use App\Models\Product;
use App\Models\PaymentTemplate;
use App\Enums\NavigationGroup;
use Filament\Schemas\Schema;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use App\Filament\Resources\Contracts\ContractResource\RelationManagers\ScheduleItemsRelationManager;

use App\Filament\Resources\Contracts\Schemas\ContractForm;

class ContractResource extends Resource
{
    protected static ?string $model = Contract::class;
    protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-document-text';
    protected static string | \UnitEnum | null $navigationGroup = NavigationGroup::TRANSACTION->value;
    protected static ?int $navigationSort = 4;

    protected static ?string $modelLabel = 'Hợp đồng';
    protected static ?string $pluralModelLabel = 'Hợp đồng';

    public static function form(Schema $schema): Schema
    {
        return ContractForm::configure($schema);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('contract_number')->label('Số HĐ')->searchable(),
                Tables\Columns\TextColumn::make('product.code')->label('Sản phẩm'),
                Tables\Columns\TextColumn::make('total_value')->label('Giá trị')->money('VND'),
            ]);
    }

    public static function getRelations(): array { return [ScheduleItemsRelationManager::class]; }

    public static function getPages(): array
    {
        return [
            'index' => Pages\ListContracts::route('/'),
            'create' => Pages\CreateContract::route('/create'),
            'edit' => Pages\EditContract::route('/{record}/edit'),
        ];
    }
}
