<?php
/**
 *
 * @date 2022-3-30
 * @author JZW
 **/


namespace Game\Model\Friend;


use Framework\Logic\TemplateHelp;
use Game\Constant\ConstTemplate\TemplateConst;
use Game\Constant\TemplateDefine;
use Game\Data\Friends\FriendsBlackData;
use Game\Data\Friends\FriendsData;

class FriendBlackModel
{
    use TemplateHelp;

    private int $playerId;
    private int $respondentPlayerId;
    private FriendsBlackData $black;

    public function setPlayerId($playerId)
    {
        $this->playerId = $playerId;
    }

    public function getPlayerId(): int
    {
        return $this->playerId;
    }

    public function setRespondentPlayerId($respondentPlayerId)
    {
        $this->respondentPlayerId = $respondentPlayerId;
    }

    public function __construct()
    {
        $this->black = new FriendsBlackData();
    }

    //添加好友到黑名单
    public function addBlack(): bool
    {
        $this->black->playerId = $this->playerId;
        $this->black->respondentPlayerId = $this->respondentPlayerId;
        return $this->black->saveDB();
    }
    //删除黑名单上的好友
    public function delBlack(&$ret): bool
    {
        $this->black->playerId = $this->playerId;
        $this->black->respondentPlayerId = $this->respondentPlayerId;
        return $this->black->deleteDB($ret);
    }

    public function searchList(): array
    {
        $ret = array();
        $this->black->playerId = $this->playerId;
        if (!$this->black->getList($ret)){
            return [];
        }
        return $ret;
    }

    //检查对方是否在黑名单
    public function checkInBlack(): bool
    {
        $this->black->playerId = $this->playerId;
        $this->black->respondentPlayerId = $this->respondentPlayerId;
        $this->black->getOneFriend($data);
        return strlen($data) != 0;
    }
}