<?php

namespace Tests\Feature;

use App\Support\OwnerRegistration;
use App\User;
use Tests\TestCase;

class OwnerRegistrationDisabledTest extends TestCase
{
    /**
     * @dataProvider ownerRegistrationEndpoints
     */
    public function test_owner_registration_is_disabled($uri, array $payload)
    {
        $response = $this->post($uri, $payload);

        $response->assertStatus(200);
        $response->assertJson([
            'status' => 0,
            'message' => OwnerRegistration::DISABLED_MESSAGE,
            'url' => OwnerRegistration::RESIDENT_SIGNUP_URL
        ]);
    }

    public function ownerRegistrationEndpoints()
    {
        return [
            'v1 full registration' => ['/api/v1/account/register', ['type' => User::OWNER]],
            'v1 short registration' => ['/api/v1/account/register-2', ['type' => User::OWNER]],
            'v2 registration' => ['/api/v2/account/register', ['type' => User::OWNER]],
            'public web registration' => ['/process-register', ['type' => User::OWNER]],
            'legacy landlord registration' => ['/process-register-qlnt', []],
            'legacy admin registration' => [
                '/admin/process-register',
                [
                    'type' => User::OWNER,
                    'email' => 'owner@example.com',
                    'phone' => '0900000000'
                ]
            ]
        ];
    }

    /**
     * @dataProvider renterRegistrationEndpoints
     */
    public function test_renter_registration_is_not_blocked($uri, $expectedStatus)
    {
        $response = $this->post($uri, ['type' => User::RENTER]);

        $response->assertStatus(200);
        $response->assertJson(['status' => $expectedStatus]);
        $this->assertNotSame(
            OwnerRegistration::DISABLED_MESSAGE,
            $response->json('message')
        );
    }

    public function renterRegistrationEndpoints()
    {
        return [
            'v1 full registration' => ['/api/v1/account/register', 0],
            'v1 short registration' => ['/api/v1/account/register-2', 0],
            'v2 registration' => ['/api/v2/account/register', 0],
            'public web registration' => ['/process-register', 2]
        ];
    }
}
