-- =====================================================
-- AutoSupirkimas - MySQL duomenų bazės schema
-- PHP 8.2 / Laravel 11 / MySQL 8
-- =====================================================


-- -----------------------------------------------------
-- Lentelė: migrations (Laravel migracijų sekimas)
-- -----------------------------------------------------
CREATE TABLE `migrations` (
    `id` int unsigned NOT NULL AUTO_INCREMENT,
    `migration` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
    `batch` int NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `migrations` (`migration`, `batch`) VALUES
('0001_01_01_000000_create_users_table', 1),
('0001_01_01_000001_create_cache_table', 1),
('2024_01_01_000001_create_car_requests_table', 1),
('2024_01_01_000002_create_car_request_photos_table', 1);

-- -----------------------------------------------------
-- Lentelė: sessions (Sesijos)
-- -----------------------------------------------------
CREATE TABLE `sessions` (
    `id` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
    `user_id` bigint unsigned DEFAULT NULL,
    `ip_address` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
    `user_agent` text COLLATE utf8mb4_unicode_ci,
    `payload` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
    `last_activity` int NOT NULL,
    PRIMARY KEY (`id`),
    KEY `sessions_user_id_index` (`user_id`),
    KEY `sessions_last_activity_index` (`last_activity`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- -----------------------------------------------------
-- Lentelė: car_requests (Automobilių užklausos)
-- -----------------------------------------------------
CREATE TABLE `car_requests` (
    `id` bigint unsigned NOT NULL AUTO_INCREMENT,
    `name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
    `phone` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
    `email` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
    `city` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
    `make` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
    `model` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
    `year` int DEFAULT NULL,
    `fuel_type` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
    `transmission` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
    `mot_valid_until` date DEFAULT NULL,
    `mileage` int DEFAULT NULL,
    `desired_price` int DEFAULT NULL,
    `comment` text COLLATE utf8mb4_unicode_ci,
    `status` enum('new','contacted','offer_sent','closed') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'new',
    `admin_note` text COLLATE utf8mb4_unicode_ci,
    `ip_address` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
    `user_agent` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
    `created_at` timestamp NULL DEFAULT NULL,
    `updated_at` timestamp NULL DEFAULT NULL,
    PRIMARY KEY (`id`),
    KEY `car_requests_status_index` (`status`),
    KEY `car_requests_city_index` (`city`),
    KEY `car_requests_make_index` (`make`),
    KEY `car_requests_created_at_index` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- -----------------------------------------------------
-- Lentelė: car_request_photos (Užklausų nuotraukos)
-- -----------------------------------------------------
CREATE TABLE `car_request_photos` (
    `id` bigint unsigned NOT NULL AUTO_INCREMENT,
    `car_request_id` bigint unsigned NOT NULL,
    `path` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
    `original_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
    `size` int NOT NULL,
    `mime` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
    `created_at` timestamp NULL DEFAULT NULL,
    `updated_at` timestamp NULL DEFAULT NULL,
    PRIMARY KEY (`id`),
    KEY `car_request_photos_car_request_id_foreign` (`car_request_id`),
    CONSTRAINT `car_request_photos_car_request_id_foreign` FOREIGN KEY (`car_request_id`) REFERENCES `car_requests` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- -----------------------------------------------------
-- Lentelė: jobs (Laravel eilės - optional)
-- -----------------------------------------------------
CREATE TABLE `jobs` (
    `id` bigint unsigned NOT NULL AUTO_INCREMENT,
    `queue` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
    `payload` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
    `attempts` tinyint unsigned NOT NULL,
    `reserved_at` int unsigned DEFAULT NULL,
    `available_at` int unsigned NOT NULL,
    `created_at` int unsigned NOT NULL,
    PRIMARY KEY (`id`),
    KEY `jobs_queue_index` (`queue`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- -----------------------------------------------------
-- Lentelė: failed_jobs (Nepavykusios užduotys)
-- -----------------------------------------------------
CREATE TABLE `failed_jobs` (
    `id` bigint unsigned NOT NULL AUTO_INCREMENT,
    `uuid` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
    `connection` text COLLATE utf8mb4_unicode_ci NOT NULL,
    `queue` text COLLATE utf8mb4_unicode_ci NOT NULL,
    `payload` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
    `exception` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
    `failed_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    UNIQUE KEY `failed_jobs_uuid_unique` (`uuid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


-- =====================================================
-- PABAIGA
-- =====================================================
--
-- Admin prisijungimas:
-- El. paštas: admin@autosupirkimas.lt
-- Slaptažodis: admin123
--
-- SVARBU: Pakeiskite admin slaptažodį produkcijoje!
-- =====================================================
