<?php

namespace Database\Seeders;

use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject;
use App\Classes\Modules\Addresses\Processors\CreateAddressFromOldAddressProcessor;
use App\Classes\Modules\Addresses\Services\CreatesAddress;
use App\Classes\Modules\Companies\DataTransferObjects\CompanyConnectionObject;
use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject;
use App\Classes\Modules\Companies\Processors\CreateCompanyModuleProcessor;
use App\Classes\Modules\Companies\Processors\CreateCompanyProcessor;
use App\Classes\Modules\Companies\Services\ApprovesCompanyConnection;
use App\Classes\Modules\Companies\Services\CreatesCompany;
use App\Classes\Modules\Companies\Services\CreatesCompanyConnection;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Companies\Services\UpdatesCompanyStatus;
use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject;
use App\Classes\Modules\Contacts\Processors\CreateContactProcessor;
use App\Classes\Modules\Contacts\Services\CreatesContact;
use App\Classes\ValueObjects\Constants\AddressType;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\CompanyType;
use App\Classes\ValueObjects\Constants\BusinessType;
use App\Classes\ValueObjects\Constants\WarehouseReferences;
use App\Models\CompanyModule;
use App\Models\OldCompany;
use Illuminate\Database\Seeder;

use App\Models\Company;

class FoshanWarehouseTableSeeder extends Seeder
{

    /** @var CreateCompanyProcessor */
    private $createCompanyProcessor;

    /** @var UpdatesCompanyStatus*/
    private $updatesCompanyStatus;

    /** @var CreateCompanyModuleProcessor */
    private $createCompanyModuleProcessor;

    /** @var CreateContactProcessor */
    private $createContactProcessor;

    /** @var CreatesCompanyConnection */
    private $createsCompanyConnection;

    /** @var ApprovesCompanyConnection */
    private $approvesCompanyConnection;

    /** @var CreateAddressFromOldAddressProcessor */
    private $createAddressFromOldAddressProcessor;

    /** @var CreatesAddress */
    private $createsAddress;

    /** @var FetchesCompany */
    private $fetchesCompany;

    /** @var CreatesContact */
    private $createsContact;

    /**
     * ModernWarehouseTableSeeder constructor.
     * @param CreateCompanyProcessor $createCompanyProcessor
     * @param UpdatesCompanyStatus $updatesCompanyStatus
     * @param CreateCompanyModuleProcessor $createCompanyModuleProcessor
     * @param CreateContactProcessor $createContactProcessor
     * @param CreatesCompanyConnection $createsCompanyConnection
     * @param ApprovesCompanyConnection $approvesCompanyConnection
     * @param CreateAddressFromOldAddressProcessor $createAddressFromOldAddressProcessor
     * @param CreatesAddress $createsAddress
     * @param FetchesCompany $fetchesCompany
     * @param CreatesContact $createsContact
     */
    public function __construct(CreateCompanyProcessor $createCompanyProcessor, UpdatesCompanyStatus $updatesCompanyStatus, CreateCompanyModuleProcessor $createCompanyModuleProcessor, CreateContactProcessor $createContactProcessor, CreatesCompanyConnection $createsCompanyConnection, ApprovesCompanyConnection $approvesCompanyConnection, CreateAddressFromOldAddressProcessor $createAddressFromOldAddressProcessor, CreatesAddress $createsAddress, FetchesCompany $fetchesCompany, CreatesContact $createsContact)
    {
        $this->createCompanyProcessor = $createCompanyProcessor;
        $this->updatesCompanyStatus = $updatesCompanyStatus;
        $this->createCompanyModuleProcessor = $createCompanyModuleProcessor;
        $this->createContactProcessor = $createContactProcessor;
        $this->createsCompanyConnection = $createsCompanyConnection;
        $this->approvesCompanyConnection = $approvesCompanyConnection;
        $this->createAddressFromOldAddressProcessor = $createAddressFromOldAddressProcessor;
        $this->createsAddress = $createsAddress;
        $this->fetchesCompany = $fetchesCompany;
        $this->createsContact = $createsContact;
    }


    /**
     * Run the database seeds.
     *
     * @return void
     * @throws \App\Classes\Exceptions\AccessForbiddenException
     * @throws \App\Classes\Exceptions\MalformedRequestException
     * @throws \App\Classes\Exceptions\RequestValidationException
     */
    public function run()
    {
        /** @var Company $company */
        $company = $this->fetchesCompany->execute(['reference' => 'MODERN']);

        // YD_FS_WEST_MALAYSIA - FS-V01
        /** @var CompanyModule $companyModule */
        $companyModule = $this->createCompanyModuleProcessor->execute($company, BusinessType::WAREHOUSE);
        $companyModule->update(['name' => 'Foshan', 'reference' => WarehouseReferences::YD_FS_WEST_MALAYSIA]);

        $address = new AddressObject('广东省 佛山市 南海区 狮山镇北园东路6号D幢1楼', '', 2, 35, 638, 528225, AddressType::DELIVERY, ApprovalStatus::APPROVED);
        $contact = new ContactObject('郑佳鹏', '18520607573', '', '');

        $this->createsAddress->execute($companyModule, $address);
        $this->createsContact->execute($companyModule, $contact);

        // FS_EAST_MALAYSIA - FS-V02
        /** @var CompanyModule $companyModule */
        $companyModule = $this->createCompanyModuleProcessor->execute($company, BusinessType::WAREHOUSE);
        $companyModule->update(['name' => 'Foshan', 'reference' => WarehouseReferences::YD_FS_EAST_MALAYSIA]);

        $address = new AddressObject('广东省 佛山市 南海区 狮山镇北园东路6号C幢1楼', '', 2, 35, 638, 528225, AddressType::DELIVERY, ApprovalStatus::APPROVED);
        $contact = new ContactObject('游万彬', '18520607573', '', '');

        $this->createsAddress->execute($companyModule, $address);
        $this->createsContact->execute($companyModule, $contact);
    }
}
