<?php

class ModelTotalMatera extends Model {
  public function getTotal(&$total_data, &$total){

    $paymentMethod = $this->session->data['payment_method'] ?? null;

    if (isset($paymentMethod) && ($paymentMethod['code'] == Type_materaConfigs::Tp_NameModule)) {

        $this->language->load('total/matera');
        $this->load->helper('ftr_geral');
        $desconto = false;

        if (!$paymentMethod['code_type']) {
            return false;
        }

        $matera_pix = $this->config->get('matera_pix');
     
        if ($matera_pix) {
            $desconto = ftr_geral::getPaymentDiscount([$matera_pix], $total, $this->cart->getTotal());
            $title = $this->language->get('text_discount_pix');
        }
      
        if (!$desconto) {
            return false;
        }

        $total -= $desconto * -1;

        $total_data[] = [
            'code' => Type_materaConfigs::Tp_NameModule,
            'title' => $title,
            'text' => $this->currency->format($desconto),
            'value' => $desconto,
            'sort_order' => $this->config->get('matera_discount_order')
        ];

        return; 
    } 

    return false;
  }

}
