import json

from payrollservice.util.masterutil import payrolldeduction_val


class EmployeePaystructure_detailsResponse:
    id = None
    emp_pay = None
    paycomponent = None
    paycomponent_type = None
    paycomponent_percentage = None
    is_deduction = None
    amount = None
    company_contribution = None
    type = None
    from_date = None
    to_date = None
    segment = None

    def get(self):
        return json.dumps(self, default=lambda o: o.__dict__,
                          sort_keys=True, indent=4)

    def set_id(self, id):
        self.id = id

    def set_emp_pay(self, emp_pay):
        self.emp_pay = emp_pay

    def set_paycomponent(self, paycomponent):
        self.paycomponent = paycomponent

    def set_paycomponent_type(self, paycomponent_type):
        self.paycomponent_type = paycomponent_type

    def set_paycomponent_percentage(self, paycomponent_percentage):
        self.paycomponent_percentage = str(paycomponent_percentage)

    def set_is_deduction(self, is_deduction):
        self.is_deduction = is_deduction

    def set_amount(self, amount):
        self.amount = str(amount)
    def set_paycomponent_val(self,paycomponent,arr):
        self.paycomponent = None
        for i in arr:
            if i.id == paycomponent:
                self.paycomponent =i
                break
            else:
                pass
        # self.paycomponent = paycomponent_type(paycomponent)


    def set_company_contribution(self, company_contribution):
        self.company_contribution = company_contribution

    def set_company_contribution_val(self, company_contribution, arr):
        self.company_contribution = None
        for i in arr:
            if i.id == company_contribution:
                self.company_contribution = i
                break
            else:
                pass

    def set_type(self, type):
        self.type = payrolldeduction_val(type)

    def set_from_date(self, from_date):
        self.from_date = str(from_date)

    def set_to_date(self, to_date):
        self.to_date = str(to_date)

    def set_employee_id_val(self, employee_id, arr):
        self.employee = None
        for i in arr:
            if i.id == employee_id:
                self.employee = i
                break

    def set_payable_days(self, payable_days):
        self.payable_days = payable_days

    def set_payroll_date(self, payroll_date):
        self.payroll_date = str(payroll_date)

    def set_employee_id(self,employee_id):
        self.employee_id = employee_id

    def set_segment(self, segment):
        self.segment = segment

    def set_segment_data(self, segment, arr):
        self.segment = None
        for i in arr:
            if i.id == segment:
                self.segment = i
                break

    def set_cc_total(self, cc_total):
        self.cc_total = str(cc_total)

    def set_yearly_cc_total(self, total):
        self.yearly_cc_total = str(total * 12)

    def set_total(self, total):
        self.total = str(total)

    def set_yearly_total(self, total):
        self.yearly_total = str(total * 12)

    def set_yearly_amount(self, amount):
        self.yearly_amount = str(amount * 12)

    def set_Annual_bonus_total(self, bonus):
        self.total_bonus = str(bonus)

    def set_Yearly_Annual_bonus_total(self, bonus):
        self.yearly_bonus_total = str(bonus * 12)

    def set_total_component_amount(self, amount):
        self.total_component_amount = str(amount)

    def set_cc_total1(self, cc_total):
        self.cc_sum = str(cc_total)

    def set_yearly_cc_total1(self, total):
        self.yearly_cc_sum = str(total * 12)

    # def set_company_contribution_values(self, company_contribution, arr,obj):
    #     arr_dta = []
    #     for i in arr:
    #         for j in company_contribution:
    #             if i.id == j:
    #                 data = {"paycomponent": j, "company_contribution": True, "paycomponent_name": i.name,
    #                         "max_amount": i.amount, "paycomponent_percentage": i.percentage}
    #                 arr_dta.append(data)
    #                 for k in obj:
    #                     for j in arr_dta:
    #                         if k.paycomponent == j['paycomponent']:
    #                             j.__setitem__("details_id", k.id)
    #                             j.__setitem__("details_amount", str(k.amount))
    #                     continue
    #     return arr_dta