<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class ExtendJobsForAdvancedFilters extends Migration
{
    public function up(): void
    {
        $this->forge->addColumn('jobs', [
            'city'    => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true, 'after' => 'location'],
            'country' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true, 'after' => 'city'],
            'is_visa_sponsorship'   => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 0, 'after' => 'is_hybrid'],
            'is_fresh_graduate_ok'  => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 0, 'after' => 'is_visa_sponsorship'],
            'is_easy_apply'         => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 1, 'after' => 'is_fresh_graduate_ok'],
        ]);
        $this->db->query('ALTER TABLE jobs ADD INDEX idx_jobs_city (city)');
        $this->db->query('ALTER TABLE jobs ADD INDEX idx_jobs_country (country)');
    }

    public function down(): void
    {
        $this->forge->dropColumn('jobs', ['city', 'country', 'is_visa_sponsorship', 'is_fresh_graduate_ok', 'is_easy_apply']);
    }
}
