# -*- coding: utf-8 -*-
from ppms import ppms
from ppms.migration import SQLPacket, PacketCategory, MaxVersionDependency, VersionType
from ppms.portfolio.utils import set_pr_code_color


class PortfolioSimulationColors(SQLPacket):
    """Initializes project colors for the new portfolio simulation."""
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 20085
    
    def get_dependencies(self):
        return MaxVersionDependency(version='39.5.9', version_type=VersionType.CUSTOMIZING),
    
    def fix(self, packet_runner):
        
        # initialise color codes in DT858
        pr_report_assignments = ppms.db_select("""select DI023102, DI023101, DI062360 from DT858""")
        for assignment in pr_report_assignments:
            portfolio_id = assignment[0]
            pr_id = assignment[1]
            report_id = assignment[2]
            set_pr_code_color(portfolio_id, pr_id, report_id, save=True)
        
        return self.success()
