package com.brilliance.isc.common.component;

import com.brilliance.isc.bo.model.Lidgrp;
import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.trnmod.service.TrnmodService;
import com.brilliance.mda.runtime.mda.util.Dates;
import com.brilliance.mda.runtime.mda.util.MdaUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

@Component
public class LitmodComponent {

    @Autowired
    private TrnmodService trnmodService;

    /**
     * source:litmod.0000.script
     */
    public void sav(Lidgrp lidgrp, BigDecimal cshpct) {
        // saves contract including texts. CBS resp. of transaction
        if (MdaUtils.isEmpty(lidgrp.getRec().getCredat())) {
            lidgrp.getRec().setCredat(Dates.today());
        }
        String frm = SettleContext.getTransName();
        if (MdaUtils.compareTo(frm, "LITOPN") == 0) {
            lidgrp.getRec().setCredat(Dates.today());
        }
        switch (frm) {
            case "LITOPN":
            case "LITAME":
            case "LITCAN":
            case "LITENG":
            case "LITROP":
            case "LITDLA":
            case "LITROG":
            case "DITOPN":
            case "DITAME":
            case "DITCAN":
            case "DITDLA":
            case "DITENG":
                lidgrp.getRec().setCshpct(cshpct);
                break;
        }
        trnmodService.trnStoreContract(lidgrp);

    }

}
