from customer_services.interactor.update_customer.dto import UpdateCustomerRequest
from customer_services.model import Customer, Address
from customer_services.model.repository import CustomerRepository
from customer_services.service import GetCustomerService


class UpdateCustomerInteractor:
    def __init__(self, customer_repository, get_customer_service):
        # type: (CustomerRepository, GetCustomerService) -> None

        self.customer_repository = customer_repository
        self.get_customer_service = get_customer_service
    
    def update_customer(self, request):
        # type: (UpdateCustomerRequest) -> None

        customer = self.get_customer_service.get_customer(request.phone)
        
        address = Address(customer.address.address_id,
                          request.zip_code,
                          request.city,
                          request.street,
                          request.neighborhood,
                          request.number,
                          request.complement,
                          request.reference_point)
        customer = Customer(request.phone, request.document, request.name, address)
        self.customer_repository.update_customer(customer)
