parameters:
    import.configuration.field.xlsx:
        entity: App\Entity\Field
        key: name
        create: true
        properties:
            '[FieldName]':
                property: name
                type: string
            '[FieldSubdivision]':
                property: subdivision
                type: App\Entity\Dictionary\Subdivision
            '[FieldSquare]':
                property: tillableArea
                type: string
            '[Location]':
                property: location
                type: App\Entity\Dictionary\Location

    import.configuration.field.json:
        entity: App\Entity\Field
        key: name
        create: false
        properties:
            '[geometry][coordinates]':
                property: coordinates
            '[properties][name]':
                property: name

    import.configuration.land.xlsx:
        entity: App\Entity\Land
        key: landNumber
        create: true
        validation_modifier: '[NoCadastralNumber]'
        properties:
            '[NoCadastralNumber]':
                property: isCadastralNumberNotExists
                type: bool
            '[Number]':
                property: landNumber
                type: string
            '[Area]':
                property: cadastralArea
                type: string
            '[NGO1995]':
                property: ngo1995
                type: string
            '[NGOCurrent]':
                property: ngoCurrent
                type: string
            '[LandType]':
                property: landType
                type: App\Entity\Dictionary\LandType
            '[LandPurpose]':
                property: landPurpose
                type: App\Entity\Dictionary\LandPurpose
            '[Location]':
                property: location
                type: App\Entity\Dictionary\Location

    import.configuration.land.json:
        entity: App\Entity\Land
        key: landNumber
        create: false
        properties:
            '[geometry][coordinates]':
                property: coordinates
            '[properties][cadastralNumber]':
                property: landNumber

    import.configuration.agreement.xlsx:
        entity: App\Entity\Agreement
        key: agreementNumber
        create: true
        validation_modifier: '[Type]'
        properties:
            '[Land]':
                property: land
                type: App\Entity\Land
            '[SubType]':
                property: subtype
                type: ?int
            '[Type]':
                property: type
                type: int
            '[TenantOrganization]':
                property: tenantOrganization
                type: App\Entity\Dictionary\Counterparty
            '[Landlord]':
                property: landlord
                type: App\Entity\Dictionary\Counterparty
            '[AgreementNumber]':
                property: agreementNumber
                type: string
            '[DateOfCreation]':
                property: dateOfCreation
                type: DateTime
            '[ValidFromDate]':
                property: validFromDate
                type: DateTime
            '[ValidByDate]':
                property: validByDate
                type: DateTime
            '[Share]':
                property: share
                type: string
            '[NgoCurrent]':
                property: ngoCurrent
                type: string
            '[RentPercentage]':
                property: rentPercentage
                type: ?string
            '[RentAmount]':
                property: rentAmount
                type: string
            '[State]':
                property: state
                type: App\Entity\Dictionary\ContractState
            '[DateOfRegistration]':
                property: dateOfRegistration
                type: DateTime
    import.configuration.counterparty.xlsx:
        entity: App\Entity\Dictionary\Counterparty
        key: code
        create: true
        validation_modifier: '[Type]'
        properties:
            '[Type]':
                property: type
                type: int
            '[Code]':
                property: code
                type: string
            '[PassportNumber]':
                property: passportNumber
                type: ?string
            '[Name]':
                property: name
                type: string

    import.configuration.land.kml:
        entity: App\Entity\Land
        key: landNumber
        create: false
        properties:
            '[coordinates]':
                property: coordinates
            '[properties][name]':
                property: landNumber

    import.configuration.field.kml:
        entity: App\Entity\Field
        key: name
        create: false
        properties:
            '[coordinates]':
                property: coordinates
            '[properties][name]':
                property: name

services:

    PhpOffice\PhpSpreadsheet\Reader\Xlsx: ~
    Symfony\Component\ExpressionLanguage\ExpressionLanguage: ~

    import.handler.item:
        class: App\Service\Import\Handler\ItemHandler
        abstract: true
        public: true
        autowire: false
        arguments:
            $constraintsProvider: '@App\Service\Import\Validator\ConstraintsProvider'
            $validator: '@App\Service\Import\Validator\Validator'
            $mapper: '@App\Service\Import\Mapper\EntityMapper'
            $entityManager: '@Doctrine\ORM\EntityManagerInterface'
            $transformer: '@App\Service\Import\Transformer\ArrayTransformer'
            $validationGroupResolver: '@App\Service\Validation\Resolver\ValidationGroupResolverInterface'
            $propertyAccessor: '@Symfony\Component\PropertyAccess\PropertyAccessorInterface'
            $authorizationChecker: '@App\Service\Import\Security\PersistAuthorizationCheckerInterface'

    import.transformer.chain:
        class: App\Service\Import\Transformer\ChainValueTransformer
        arguments:
            $transformers:
                - '@App\Service\Import\Transformer\ScalarValueTransformer'
                - '@App\Service\Import\Transformer\EntityValueTransformer'
                - '@App\Service\Import\Transformer\StringToDateTimeTransformer'

    import.handler.agreement.xlsx:
        parent: 'import.handler.item'
        arguments:
            $configuration: '%import.configuration.agreement.xlsx%'
    import.handler.counterparty.xlsx:
        parent: 'import.handler.item'
        arguments:
            $configuration: '%import.configuration.counterparty.xlsx%'
    import.handler.field.xlsx:
        parent: 'import.handler.item'
        arguments:
            $configuration: '%import.configuration.field.xlsx%'
    import.handler.field.json:
        parent: 'import.handler.item'
        arguments:
            $configuration: '%import.configuration.field.json%'
    import.handler.land.xlsx:
        parent: 'import.handler.item'
        arguments:
            $configuration: '%import.configuration.land.xlsx%'
    import.handler.land.json:
        parent: 'import.handler.item'
        arguments:
            $configuration: '%import.configuration.land.json%'
    import.handler.land.kml:
        parent: 'import.handler.item'
        arguments:
            $configuration: '%import.configuration.land.kml%'
    import.handler.field.kml:
        parent: 'import.handler.item'
        arguments:
            $configuration: '%import.configuration.field.kml%'

    App\Service\Import\Importer\ImporterInterface:
        alias: App\Service\Import\Importer\ProxyImporter

    importer:
        class: App\Service\Import\Importer\Importer
        abstract: true
        arguments:
            $logger: '@logger'
            $result: '@App\Service\Import\Result\ResultInterface'
        tags:
            - { name: monolog.logger, channel: import }

    importer.field.xlsx:
        class: App\Service\Import\Importer\Importer
        parent: importer
        public: true
        arguments:
            $extractor: '@App\Service\Import\Extractor\XlsxExtractor'
            $handler: '@import.handler.field.xlsx'
    importer.field.json:
        class: App\Service\Import\Importer\Importer
        parent: importer
        public: true
        arguments:
            $extractor: '@App\Service\Import\Extractor\JsonExtractor'
            $handler: '@import.handler.field.json'
    importer.land.xlsx:
        class: App\Service\Import\Importer\Importer
        parent: importer
        public: true
        arguments:
            $extractor: '@App\Service\Import\Extractor\XlsxExtractor'
            $handler: '@import.handler.land.xlsx'
    importer.land.json:
        class: App\Service\Import\Importer\Importer
        parent: importer
        public: true
        arguments:
            $extractor: '@App\Service\Import\Extractor\JsonExtractor'
            $handler: '@import.handler.land.json'
    importer.counterparty.xlsx:
        class: App\Service\Import\Importer\Importer
        parent: importer
        public: true
        arguments:
            $extractor: '@App\Service\Import\Extractor\XlsxExtractor'
            $handler: '@import.handler.counterparty.xlsx'
    importer.agreement.xlsx:
        class: App\Service\Import\Importer\Importer
        parent: importer
        public: true
        arguments:
            $extractor: '@App\Service\Import\Extractor\XlsxExtractor'
            $handler: '@import.handler.agreement.xlsx'
    importer.land.kml:
        class: App\Service\Import\Importer\Importer
        parent: importer
        public: true
        arguments:
            $extractor: '@App\Service\Import\Extractor\KmlExtractor'
            $handler: '@import.handler.land.kml'
    importer.field.kml:
        class: App\Service\Import\Importer\Importer
        parent: importer
        public: true
        arguments:
            $extractor: '@App\Service\Import\Extractor\KmlExtractor'
            $handler: '@import.handler.field.kml'
