package com.ikon.projectmanagement.mapper;

import org.springframework.stereotype.Component;

import com.ikon.projectmanagement.dto.request.ProductExpenseRequestDto;
import com.ikon.projectmanagement.dto.request.ProjectRequestDto;
import com.ikon.projectmanagement.dto.response.ProjectResponseDto;
import com.ikon.projectmanagement.entity.ProductOfProjectExpenseDetail;
import com.ikon.projectmanagement.entity.Project;

@Component
public class ProjectMapper {

    public Project toEntity(ProjectRequestDto dto) {
        Project project = new Project();
        mapCommonFields(dto, project);
        return project;
    }

    public void updateEntityFromDto(ProjectRequestDto dto, Project project) {
        mapCommonFields(dto, project);
    }

    private void mapCommonFields(ProjectRequestDto dto, Project project) {

        project.setProjectName(dto.getProjectName());
        project.setProjectManager(dto.getProjectManager());
        project.setProjectStatus(dto.getProjectStatus());
        project.setProjectNumber(dto.getProjectNumber());
        project.setParentProjectNo(dto.getParentProjectNo());
        project.setContractNumber(dto.getContractNumber());
        project.setProjectClient(dto.getProjectClient());
        project.setProjectCity(dto.getProjectCity());
        project.setProjectCountry(dto.getProjectCountry());
        project.setCurrency(dto.getCurrency());
        project.setProjectImage(dto.getProjectImage());
        project.setContractUpload(dto.getContractUpload());
        project.setSource(dto.getSource());
        project.setProductType(dto.getProductType());
        project.setExpenses(dto.getExpenses());
        project.setFormattedActualRevenueIncludingVAT_deal(dto.getFormattedActualRevenueIncludingVAT_deal());
        project.setIsCompleted(dto.getIsCompleted());
        project.setGroupNotExist(dto.getGroupNotExist());
        project.setIsDebtRevenue_deal(dto.getIsDebtRevenue_deal());
        project.setProjectDescription(dto.getProjectDescription());

        project.setProjectStartDate(dto.getProjectStartDate());
        project.setContractedStartDate(dto.getContractedStartDate());
        project.setContractedEndDate(dto.getContractedEndDate());

        project.setProjectTeam(dto.getProjectTeam());
        project.setProjectTeamUnderProjectManager(dto.getProjectTeamUnderProjectManager());
        project.setProjectTeamUnderProjectManagerDelegates(dto.getProjectTeamUnderProjectManagerDelegates());

        project.setParticipants(dto.getParticipants());
        project.setContractedProductIdentifierWiseDataObj(dto.getContractedProductIdentifierWiseDataObj());

    }

    public ProjectResponseDto toResponse(Project project) {

        if (project == null)
            return null;

        ProjectResponseDto dto = new ProjectResponseDto();

        dto.setProjectIdentifier(project.getProjectIdentifier());
        dto.setProjectName(project.getProjectName());
        dto.setProjectManager(project.getProjectManager());
        dto.setProjectStatus(project.getProjectStatus());
        dto.setProjectNumber(project.getProjectNumber());
        dto.setParentProjectNo(project.getParentProjectNo());
        dto.setContractNumber(project.getContractNumber());

        dto.setProjectClient(project.getProjectClient());
        dto.setProjectCity(project.getProjectCity());
        dto.setProjectCountry(project.getProjectCountry());
        dto.setCurrency(project.getCurrency());

        dto.setProjectImage(project.getProjectImage());
        dto.setContractUpload(project.getContractUpload());

        dto.setSource(project.getSource());
        dto.setProductType(project.getProductType());
        dto.setExpenses(project.getExpenses());

        dto.setFormattedActualRevenueIncludingVAT_deal(
                project.getFormattedActualRevenueIncludingVAT_deal());
        dto.setIsCompleted(project.getIsCompleted());
        dto.setGroupNotExist(project.getGroupNotExist());
        dto.setIsDebtRevenue_deal(project.getIsDebtRevenue_deal());

        dto.setProjectDescription(project.getProjectDescription());

        dto.setProjectStartDate(project.getProjectStartDate());
        dto.setContractedStartDate(project.getContractedStartDate());
        dto.setContractedEndDate(project.getContractedEndDate());

        dto.setProjectTeam(project.getProjectTeam());
        dto.setProjectTeamUnderProjectManager(
                project.getProjectTeamUnderProjectManager());
        dto.setProjectTeamUnderProjectManagerDelegates(
                project.getProjectTeamUnderProjectManagerDelegates());

        dto.setParticipants(project.getParticipants());
        dto.setContractedProductIdentifierWiseDataObj(
                project.getContractedProductIdentifierWiseDataObj());

        if (project.getProduct() != null) {
            dto.setProductIdentifier(project.getProduct().getProductIdentifier());
            dto.setProductType(project.getProduct().getProductType());
        }

        return dto;
    }

    
}
