package com.ikon.projectmanagement.mapper;

import org.springframework.stereotype.Component;

import com.ikon.projectmanagement.dto.request.IssueCreateRequestDto;
import com.ikon.projectmanagement.dto.response.IssueResponseDto;
import com.ikon.projectmanagement.entity.Issue;

@Component
public class IssueMapper {

    // ================= CREATE =================
    public Issue toEntity(IssueCreateRequestDto dto) {
        Issue issue = new Issue();

        issue.setIssueTitle(dto.getIssueTitle());
        issue.setIssueProbability(dto.getIssueProbability());
        issue.setGrossIssueValue(dto.getGrossIssueValue());
        issue.setProbableIssueValue(dto.getProbableIssueValue());
        issue.setProbableIssueValueInUSD(dto.getProbableIssueValueInUSD());
        issue.setIssueImpact(dto.getIssueImpact());
        issue.setIssueOwner(dto.getIssueOwner());
        issue.setIssueDescription(dto.getIssueDescription());
        issue.setMitigationAction(dto.getMitigationAction());
        issue.setFinancialIssue(dto.getFinancialIssue());
        issue.setIssueCreatedDate(dto.getIssueCreatedDate());
        issue.setIssueOptionsSelectId(dto.getIssueOptionsSelectId());
        issue.setIssueStatus(dto.getIssueStatus());
        issue.setIssueAge(dto.getIssueAge());
        issue.setEffectedSprintId(dto.getEffectedSprintId());
        issue.setProjectIdentifier(dto.getProjectIdentifier());

        return issue;
    }

    // ================= RESPONSE =================
    public IssueResponseDto toResponse(Issue issue) {
        IssueResponseDto dto = new IssueResponseDto();

        dto.setIssueId(issue.getIssueId());
        dto.setIssueTitle(issue.getIssueTitle());
        dto.setIssueProbability(issue.getIssueProbability());
        dto.setGrossIssueValue(issue.getGrossIssueValue());
        dto.setProbableIssueValue(issue.getProbableIssueValue());
        dto.setProbableIssueValueInUSD(issue.getProbableIssueValueInUSD());
        dto.setIssueImpact(issue.getIssueImpact());
        dto.setIssueOwner(issue.getIssueOwner());
        dto.setIssueDescription(issue.getIssueDescription());
        dto.setMitigationAction(issue.getMitigationAction());
        dto.setFinancialIssue(issue.getFinancialIssue());
        dto.setIssueCreatedDate(issue.getIssueCreatedDate());
        dto.setIssueOptionsSelectId(issue.getIssueOptionsSelectId());
        dto.setIssueStatus(issue.getIssueStatus());
        dto.setIssueAge(issue.getIssueAge());
        dto.setEffectedSprintId(issue.getEffectedSprintId());
        dto.setProjectIdentifier(issue.getProjectIdentifier());

        return dto;
    }

    // ================= UPDATE =================
    public void updateEntityFromDto(IssueCreateRequestDto dto, Issue issue) {

        if (dto.getIssueTitle() != null)
            issue.setIssueTitle(dto.getIssueTitle());

        if (dto.getIssueProbability() != null)
            issue.setIssueProbability(dto.getIssueProbability());

        if (dto.getGrossIssueValue() != null)
            issue.setGrossIssueValue(dto.getGrossIssueValue());

        if (dto.getProbableIssueValue() != null)
            issue.setProbableIssueValue(dto.getProbableIssueValue());

        if (dto.getProbableIssueValueInUSD() != null)
            issue.setProbableIssueValueInUSD(dto.getProbableIssueValueInUSD());

        if (dto.getIssueImpact() != null)
            issue.setIssueImpact(dto.getIssueImpact());

        if (dto.getIssueOwner() != null)
            issue.setIssueOwner(dto.getIssueOwner());

        if (dto.getIssueDescription() != null)
            issue.setIssueDescription(dto.getIssueDescription());

        if (dto.getMitigationAction() != null)
            issue.setMitigationAction(dto.getMitigationAction());

        if (dto.getFinancialIssue() != null)
            issue.setFinancialIssue(dto.getFinancialIssue());

        if (dto.getIssueCreatedDate() != null)
            issue.setIssueCreatedDate(dto.getIssueCreatedDate());

        if (dto.getIssueOptionsSelectId() != null)
            issue.setIssueOptionsSelectId(dto.getIssueOptionsSelectId());

        if (dto.getIssueStatus() != null)
            issue.setIssueStatus(dto.getIssueStatus());

        if (dto.getIssueAge() != null)
            issue.setIssueAge(dto.getIssueAge());

        if (dto.getEffectedSprintId() != null)
            issue.setEffectedSprintId(dto.getEffectedSprintId());

        if (dto.getProjectIdentifier() != null)
            issue.setProjectIdentifier(dto.getProjectIdentifier());
    }
}