<?php
namespace Incoviba\Repository\Venta;

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

class TipoEstadoCierre extends Ideal\Repository
{
    public function __construct(Define\Connection $connection)
    {
        parent::__construct($connection);
        $this->setTable('tipo_estado_cierre');
    }

    public function create(?array $data = null): Define\Model
    {
        $map = (new Implement\Repository\MapperParser(['descripcion']))
            ->register('vigente', new Implement\Repository\Mapper\Boolean('vigente'));
        return $this->parseData(new Model\Venta\TipoEstadoCierre(), $data, $map);
    }
    public function save(Define\Model $model): Define\Model
    {
        $model->id = $this->saveNew(
            ['descripcion', 'vigente'],
            [$model->descripcion, $model->vigente ? 1 : 0]
        );
        return $model;
    }
    public function edit(Define\Model $model, array $new_data): Define\Model
    {
        return $this->update($model, ['descripcion', 'vigente'], $new_data);
    }
}
