<?php

namespace app\common\repositories\dividend;

use app\common\dao\dividend\DividendLogDao;
use app\common\repositories\BaseRepository;
use app\entity\data\dividend\DividendLogEntity;

class DividendLogRepository extends BaseRepository
{

    protected $dao;

    /**
     * DividendLogRepository constructor.
     * @param DividendLogDao $dao
     */
    public function __construct(DividendLogDao $dao)
    {
        $this->dao = $dao;
    }

    /**
     * @param int $id
     * @return DividendLogEntity
     */
    public function getDividendLogEntityById(int $id): DividendLogEntity
    {
        $entityList = $this->getDividendLogEntityListByIdList([$id]);
        $entity = array_shift($entityList);
        if ($entity instanceof DividendLogEntity) {
            return $entity;
        } else {
            /** @var DividendLogEntity */
            return DividendLogEntity::newInstance();
        }
    }

    /**
     * @param array $idList
     * @return DividendLogEntity[]
     */
    public function getDividendLogEntityListByIdList(array $idList): array
    {
        return $this->dao->getDividendLogEntityListByIdList($idList);
    }

    public function create($data)
    {
        return $this->dao->create($data);
    }

    /**
     * @param DividendLogEntity $dividendLogEntity
     * @return DividendLogEntity
     */
    public function createByEntity(DividendLogEntity $dividendLogEntity): DividendLogEntity
    {
        $result = $this->create($dividendLogEntity->toUnderlineArray())->toArray();
        /** @var DividendLogEntity $entity */
        $entity = DividendLogEntity::newInstance($result);
        return $entity;
    }
}
