<?php
/*
 * The MIT License
 *
 * Copyright (c) 2026 "YooMoney", NBСO LLC
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

namespace Tests\YooKassa\Model\Notification;

use PHPUnit\Framework\TestCase;
use YooKassa\Helpers\Random;
use YooKassa\Model\Notification\AbstractNotification;

abstract class AbstractNotificationTest extends TestCase
{
    /**
     * @param array $source
     * @return AbstractNotification
     */
    abstract protected function getTestInstance(array $source);

    /**
     * @return string
     */
    abstract protected function getExpectedType();

    /**
     * @return string
     */
    abstract protected function getExpectedEvent();

    /**
     * @return array
     */
    abstract public function validDataProvider();

    /**
     * @dataProvider validDataProvider
     * @param array $value
     */
    public function testGetType(array $value)
    {
        $instance = $this->getTestInstance($value);
        self::assertEquals($this->getExpectedType(), $instance->getType());
    }

    /**
     * @dataProvider invalidConstructorTypeDataProvider
     * @expectedException \InvalidArgumentException
     * @param array $source
     */
    public function testInvalidTypeInConstructor(array $source)
    {
        $this->getTestInstance($source);
    }

    /**
     * @dataProvider validDataProvider
     * @param array $value
     */
    public function testGetEvent(array $value)
    {
        $instance = $this->getTestInstance($value);
        self::assertEquals($this->getExpectedEvent(), $instance->getEvent());
    }

    /**
     * @dataProvider invalidConstructorEventDataProvider
     * @expectedException \InvalidArgumentException
     * @param array $source
     */
    public function testInvalidEventInConstructor(array $source)
    {
        $this->getTestInstance($source);
    }

    /**
     * @dataProvider invalidTypeDataProvider
     * @expectedException \InvalidArgumentException
     * @param $value
     */
    public function testInvalidType($value)
    {
        new TestNotification($value, $this->getExpectedEvent());
    }

    /**
     * @dataProvider invalidEventDataProvider
     * @expectedException \InvalidArgumentException
     * @param $value
     */
    public function testInvalidEvent($value)
    {
        new TestNotification($this->getExpectedType(), $value);
    }

    public function invalidConstructorTypeDataProvider()
    {
        return array(
            array(array('event' => $this->getExpectedEvent(), 'type' => 'test')),
            array(array('event' => $this->getExpectedEvent(), 'type' => null)),
            array(array('event' => $this->getExpectedEvent(), 'type' => '')),
            array(array('event' => $this->getExpectedEvent(), 'type' => 1)),
            array(array('event' => $this->getExpectedEvent(), 'type' => array())),
        );
    }

    public function invalidConstructorEventDataProvider()
    {
        return array(
            array(array('type' => $this->getExpectedType(), 'event' => 'test')),
            array(array('type' => $this->getExpectedType(), 'event' => null)),
            array(array('type' => $this->getExpectedType(), 'event' => '')),
            array(array('type' => $this->getExpectedType(), 'event' => 1)),
            array(array('type' => $this->getExpectedType(), 'event' => array())),
        );
    }

    public function invalidTypeDataProvider()
    {
        return array(
            array(''),
            array(null),
            array(Random::str(40)),
            array(0),
            array(array()),
            array(new \stdClass()),
        );
    }

    public function invalidEventDataProvider()
    {
        return array(
            array(''),
            array(null),
            array(Random::str(40)),
            array(0),
            array(array()),
            array(new \stdClass()),
        );
    }
}

class TestNotification extends AbstractNotification
{
    public function __construct($type, $event)
    {
        $this->setType($type);
        $this->setEvent($event);
    }
}
