<?php
namespace Incoviba\Repository\Venta;

use Incoviba\Common\Ideal;
use Incoviba\Common\Define;
use Incoviba\Common\Implement;
use Incoviba\Model;

class Subsidio extends Ideal\Repository
{
    public function __construct(Define\Connection $connection, protected Pago $pagoRepository)
    {
        parent::__construct($connection);
        $this->setTable('subsidio');
    }

    public function create(?array $data = null): Model\Venta\Subsidio
    {
        $map = new Implement\Repository\MapperParser(['pago', 'subsidio']);
        return $this->parseData(new Model\Venta\Subsidio(), $data, $map);
    }
    public function save(Define\Model $model): Model\Venta\Subsidio
    {
        $model->id = $this->saveNew(
            ['pago', 'subsidio'],
            [$model->ahorro->id, $model->subsidio->id]
        );
        return $model;
    }
    public function edit(Define\Model $model, array $new_data): Model\Venta\Subsidio
    {
        return $this->update($model, ['pago', 'subsidio'], $new_data);
    }
}
