<?php
require_once __DIR__ . '/../../Models/Lookup.php';

class LookupController {
    public function countries() {
        $model = new Lookup('countries');
        jsonResponse(true, 'Countries loaded', $model->getActive());
    }

    public function cities() {
        $country_id = $_GET['country_id'] ?? null;
        $model = new Lookup('cities');
        
        if ($country_id) {
            $stmt = Database::getInstance()->prepare("SELECT * FROM cities WHERE status = 'active' AND country_id = ?");
            $stmt->execute([$country_id]);
            $data = $stmt->fetchAll();
        } else {
            $data = $model->getActive();
        }
        
        jsonResponse(true, 'Cities loaded', $data);
    }

    public function nationalities() {
        $model = new Lookup('nationalities');
        jsonResponse(true, 'Nationalities loaded', $model->getActive());
    }

    public function languages() {
        $model = new Lookup('languages');
        jsonResponse(true, 'Languages loaded', $model->getActive());
    }

    public function specialties() {
        $model = new Lookup('specialties');
        jsonResponse(true, 'Specialties loaded', $model->getActive());
    }

    public function skills() {
        $model = new Lookup('skills');
        jsonResponse(true, 'Skills loaded', $model->getActive());
    }

    public function accommodationTypes() {
        $model = new Lookup('accommodation_types');
        jsonResponse(true, 'Accommodation types loaded', $model->getActive());
    }

    public function serviceModels() {
        $model = new Lookup('service_models');
        jsonResponse(true, 'Service models loaded', $model->getActive());
    }

    public function documentTypes() {
        $owner_type = $_GET['owner_type'] ?? null;
        $db = Database::getInstance();
        if ($owner_type) {
            $stmt = $db->prepare("SELECT * FROM document_types WHERE status = 'active' AND owner_type = ?");
            $stmt->execute([$owner_type]);
            $data = $stmt->fetchAll();
        } else {
            $model = new Lookup('document_types');
            $data = $model->getActive();
        }
        jsonResponse(true, 'Document types loaded', $data);
    }
}
