<?php

namespace Tests\Feature;

use Tests\TestCase;

class LegacyMarketplaceRedirectTest extends TestCase
{
    /**
     * @dataProvider legacyRoomSearchUrls
     */
    public function test_itro_legacy_room_search_redirects_permanently_to_phong_chuan($uri)
    {
        $response = $this->withServerVariables([
            'HTTP_HOST' => 'itro.vn',
        ])->get($uri);

        $response->assertStatus(301);
        $response->assertRedirect('https://phongchuan.vn/tim-phong');
    }

    public function legacyRoomSearchUrls()
    {
        return [
            'old map' => ['/ban-do'],
            'old search' => ['/tim-kiem'],
            'old roommate search' => ['/tim-o-ghep'],
            'newer map' => ['/map-2'],
            'second map' => ['/ban-do-2'],
            'old room search landing' => ['/tim-phong'],
            'second old room search landing' => ['/tim-phong-2'],
        ];
    }

    public function test_legacy_landlord_page_redirects_permanently_to_phong_chuan()
    {
        $response = $this->withServerVariables([
            'HTTP_HOST' => 'itro.vn',
        ])->get('/landlord');

        $response->assertStatus(301);
        $response->assertRedirect('https://phongchuan.vn/');
    }

    public function test_legacy_tenant_page_redirects_permanently_to_phong_chuan_search()
    {
        $response = $this->withServerVariables([
            'HTTP_HOST' => 'itro.vn',
        ])->get('/tenant');

        $response->assertStatus(301);
        $response->assertRedirect('https://phongchuan.vn/tim-phong');
    }

    public function test_quan_ly_nha_tro_domain_keeps_the_existing_pages()
    {
        $landlordResponse = $this->withServerVariables([
            'HTTP_HOST' => 'quanlynhatro.com',
        ])->get('/landlord');
        $tenantResponse = $this->withServerVariables([
            'HTTP_HOST' => 'quanlynhatro.com',
        ])->get('/tenant');

        $landlordResponse->assertStatus(200);
        $landlordResponse->assertSee('https://phongchuan.vn/');
        $tenantResponse->assertStatus(200);
        $tenantResponse->assertSee('https://phongchuan.vn/tim-phong');
    }
}
