<?php

namespace Lc\CaracoleBundle\Definition\Field\Credit;

use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\CaracoleBundle\Context\MerchantContextTrait;
use Lc\CaracoleBundle\Solver\Credit\CreditHistorySolver;
use Lc\CaracoleBundle\Solver\Order\OrderPaymentSolver;
use Lc\SovBundle\Definition\Field\AbstractFieldDefinition;

class CreditHistoryFieldDefinition extends AbstractFieldDefinition
{
    use MerchantContextTrait;

    public function configureIndex(): array
    {
        return [
            'id',
            'type',
            'amount',
            'paidAt',
            'meanPayment',
            'reference',
            'comment',
        ];
    }

    public function configureForm(): array
    {
        return [
            'type',
            'amount',
            'paidAt',
            'meanPayment',
            'reference',
            'comment',
        ];
    }

    public function configureFields(): array
    {
        return [
            'id' => IdField::new('id')
                ->setSortable(true),
            'type' => ChoiceField::new('type')
                ->setChoices(
                    $this->translatorAdmin->transChoices(
                        CreditHistorySolver::getTypeChoices(),
                        'CreditHistory',
                        'type'
                    )
                )
                ->setSortable(true),
            'amount' => NumberField::new('amount')
                ->setTemplatePath('@LcCaracole/admin/credit/field/amount.html.twig')
                ->setCustomOption('appendHtml', '&euro;')
                ->setSortable(false),
            'paidAt' => DateField::new('paidAt')
                ->setFormTypeOption('required', true)
                ->setTemplatePath('@LcCaracole/admin/credit/field/paidAt.html.twig')
                ->setSortable(false),
            'meanPayment' => ChoiceField::new('meanPayment')
                ->setChoices(
                    $this->translatorAdmin->transChoices(
                        OrderPaymentSolver::getMeanPaymentChoices(),
                        'OrderPayment',
                        'meanPayment'
                    )
                )->setFormTypeOption('required', true)
                ->setTemplatePath('@LcCaracole/admin/credit/field/meanPayment.html.twig')
                ->setSortable(true),
            'reference' => TextField::new('reference')
                ->setTemplatePath('@LcCaracole/admin/credit/field/reference.html.twig')
                ->setSortable(false),
            'comment' => TextField::new('comment')
                ->setTemplatePath('@LcCaracole/admin/credit/field/comment.html.twig')
                ->setSortable(false),

        ];
    }

}