-- MotorOS / PBS Autos MySQL Database Dump
-- Generated for phpMyAdmin / MySQL / MariaDB
-- Target Database: kingsleymotors_pbsdb

SET FOREIGN_KEY_CHECKS = 0;
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
SET NAMES utf8mb4;

-- --------------------------------------------------------
-- Table structure for table `workshops`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `workshops`;
CREATE TABLE `workshops` (
  `id` VARCHAR(64) NOT NULL,
  `name` VARCHAR(255) NOT NULL,
  `email` VARCHAR(191) NOT NULL,
  `phone` VARCHAR(191) NOT NULL,
  `address` LONGTEXT NOT NULL,
  `postcode` VARCHAR(191) NOT NULL,
  `vat_registered` INT NOT NULL DEFAULT 1,
  `vat_number` VARCHAR(255) NULL,
  `logo_url` VARCHAR(255) NULL,
  `currency` VARCHAR(255) NOT NULL DEFAULT 'GBP',
  `default_labour_rate` DECIMAL(12, 2) NOT NULL DEFAULT 85.00,
  `invoice_prefix` VARCHAR(255) NOT NULL DEFAULT 'INV-',
  `next_invoice_number` INT NOT NULL DEFAULT 1042,
  `next_job_number` INT NOT NULL DEFAULT 1042,
  `next_estimate_number` INT NOT NULL DEFAULT 1042,
  `smtp_host` VARCHAR(255) NULL,
  `smtp_port` INT NULL DEFAULT 587,
  `smtp_secure` INT NULL DEFAULT 0,
  `smtp_user` VARCHAR(255) NULL,
  `smtp_pass` VARCHAR(255) NULL,
  `smtp_from_email` VARCHAR(255) NULL,
  `smtp_from_name` VARCHAR(255) NULL,
  `admin_notification_email` VARCHAR(255) NULL,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `vapid_public_key` LONGTEXT NULL,
  `vapid_private_key` LONGTEXT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `workshops`
INSERT INTO `workshops` (`id`, `name`, `email`, `phone`, `address`, `postcode`, `vat_registered`, `vat_number`, `logo_url`, `currency`, `default_labour_rate`, `invoice_prefix`, `next_invoice_number`, `next_job_number`, `next_estimate_number`, `smtp_host`, `smtp_port`, `smtp_secure`, `smtp_user`, `smtp_pass`, `smtp_from_email`, `smtp_from_name`, `admin_notification_email`, `created_at`, `vapid_public_key`, `vapid_private_key`) VALUES
('ws_pbs_autos_001', 'PBS Autos — Body Panel & Accident Damage Repairs', 'service@pbsautos.co.uk', '+44 7376 926728', '158-168 Uttoxeter Rd, Longton, Stoke-on-Trent ST3 1QH, United Kingdom', 'ST3 1QH', 1, 'GB 389 4512 88', NULL, 'GBP', 85, 'PBS-', 1007, 1007, 1002, NULL, 587, 0, NULL, NULL, NULL, NULL, NULL, '2026-09-18 14:34:00', NULL, NULL);

-- --------------------------------------------------------
-- Table structure for table `users`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
  `id` VARCHAR(64) NOT NULL,
  `workshop_id` VARCHAR(64) NOT NULL,
  `name` VARCHAR(255) NOT NULL,
  `email` VARCHAR(191) NOT NULL,
  `password_hash` VARCHAR(255) NOT NULL,
  `role` VARCHAR(191) NOT NULL,
  `speciality` VARCHAR(255) NULL,
  `phone` VARCHAR(191) NULL,
  `hourly_rate` DECIMAL(12, 2) NULL DEFAULT 50.00,
  `is_active` INT NOT NULL DEFAULT 1,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `permissions_json` LONGTEXT NULL DEFAULT '[]',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_users_email` (`email`),
  CONSTRAINT `fk_users_workshop_id_0` FOREIGN KEY (`workshop_id`) REFERENCES `workshops` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `users`
INSERT INTO `users` (`id`, `workshop_id`, `name`, `email`, `password_hash`, `role`, `speciality`, `phone`, `hourly_rate`, `is_active`, `created_at`, `permissions_json`) VALUES
('usr_admin_001', 'ws_pbs_autos_001', 'PBS Autos Admin', 'admin@pbsautos.co.uk', '$2b$10$GXfQQOkWJLHssLHdYD.6tefsRNnFmdJTSWJZPfFr4FIUeBRn2SIr.', 'ADMIN', 'Bodyshop Manager', '07700 900100', 85, 1, '2026-09-18 14:34:00', '[]'),
('usr_bookin_001', 'ws_pbs_autos_001', 'Book In Client', 'bookin@pbsautos.co.uk', '$2b$10$GXfQQOkWJLHssLHdYD.6tefsRNnFmdJTSWJZPfFr4FIUeBRn2SIr.', 'BOOKING', 'Customer Intake & Bay Allocation', '07700 900105', 50, 1, '2026-09-18 14:34:00', '[]'),
('usr_tech_chris', 'ws_pbs_autos_001', 'Chris', 'chris@pbsautos.co.uk', '$2b$10$GXfQQOkWJLHssLHdYD.6tefsRNnFmdJTSWJZPfFr4FIUeBRn2SIr.', 'SPRAYER', 'Paint Booth & Refinishing', '07700 900101', 55, 1, '2026-09-18 14:34:00', '[]'),
('usr_tech_habibi', 'ws_pbs_autos_001', 'Habibi', 'habibi@pbsautos.co.uk', '$2b$10$GXfQQOkWJLHssLHdYD.6tefsRNnFmdJTSWJZPfFr4FIUeBRn2SIr.', 'PANEL_PREP', 'Bay 1 Structural & Alignment', '07700 900102', 52, 1, '2026-09-18 14:34:00', '[]'),
('usr_tech_paajii', 'ws_pbs_autos_001', 'Paa Jii', 'paajii@pbsautos.co.uk', '$2b$10$GXfQQOkWJLHssLHdYD.6tefsRNnFmdJTSWJZPfFr4FIUeBRn2SIr.', 'PANEL_PREP', 'Bay 2 Panel Beating & Prep', '07700 900103', 52, 1, '2026-09-18 14:34:00', '[]'),
('usr_tech_ismail', 'ws_pbs_autos_001', 'Ismail', 'ismail@pbsautos.co.uk', '$2b$10$GXfQQOkWJLHssLHdYD.6tefsRNnFmdJTSWJZPfFr4FIUeBRn2SIr.', 'BOOKING', 'Booking In & Vehicle Intake', '07700 900104', 48, 1, '2026-09-18 14:34:00', '[]'),
('usr_d7a409a5', 'ws_pbs_autos_001', 'test@test.com', 'test@test.com', '$2b$10$1p31auXeMqYlyDpZ7ag4yOkj.OHfUKp3zN4oT7668N0YrqOkWJRke', 'ADMIN', NULL, '3243423', 85, 1, '2026-09-18 15:45:21', '["jobs","stages","invoices","traders","templates","reports","settings"]');

-- --------------------------------------------------------
-- Table structure for table `customers`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `customers`;
CREATE TABLE `customers` (
  `id` VARCHAR(64) NOT NULL,
  `workshop_id` VARCHAR(64) NOT NULL,
  `first_name` VARCHAR(255) NOT NULL,
  `last_name` VARCHAR(255) NOT NULL,
  `company_name` VARCHAR(255) NULL,
  `phone` VARCHAR(191) NOT NULL,
  `email` VARCHAR(191) NOT NULL,
  `address` LONGTEXT NULL,
  `postcode` VARCHAR(191) NULL,
  `notes` LONGTEXT NULL,
  `comm_pref` VARCHAR(191) NOT NULL DEFAULT 'WHATSAPP',
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_customers_workshop_id_0` FOREIGN KEY (`workshop_id`) REFERENCES `workshops` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `customers`
INSERT INTO `customers` (`id`, `workshop_id`, `first_name`, `last_name`, `company_name`, `phone`, `email`, `address`, `postcode`, `notes`, `comm_pref`, `created_at`) VALUES
('cust_eb44f7ea', 'ws_pbs_autos_001', 'test', 'test', NULL, '0342847983', 'test@gmail.com', '', '', NULL, 'WHATSAPP', '2026-10-04 00:19:25'),
('cust_6b998217', 'ws_pbs_autos_001', 'George', 'Clark', '', '07700900999', 'george.clark@example.co.uk', '', '', NULL, 'WHATSAPP', '2026-10-04 00:30:18'),
('cust_3da7ebe9', 'ws_pbs_autos_001', 'test2', 'test2', '', '0324304993', 'sams@gmail.co', '', '', NULL, 'WHATSAPP', '2026-10-04 00:36:54'),
('cust_cec7c839', 'ws_pbs_autos_001', 'test2', 'test2', NULL, '03425430094', 'test2@gmail.com', '', '', NULL, 'WHATSAPP', '2026-10-04 01:02:08'),
('cust_dd362c05', 'ws_pbs_autos_001', 'test3', 'test3', NULL, '03425430094', 'test3@gmail.com', '', '', NULL, 'WHATSAPP', '2026-10-04 01:05:01'),
('cust_9eca54bc', 'ws_pbs_autos_001', 'test4', 'test4', NULL, '03425403992', 'test4@gmail.com', '', '', NULL, 'WHATSAPP', '2026-10-04 01:15:32');

-- --------------------------------------------------------
-- Table structure for table `vehicles`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `vehicles`;
CREATE TABLE `vehicles` (
  `id` VARCHAR(64) NOT NULL,
  `workshop_id` VARCHAR(64) NOT NULL,
  `customer_id` VARCHAR(64) NOT NULL,
  `registration` VARCHAR(191) NOT NULL,
  `make` VARCHAR(255) NOT NULL,
  `model` VARCHAR(255) NOT NULL,
  `variant` VARCHAR(255) NULL,
  `vehicle_size` VARCHAR(191) NOT NULL DEFAULT 'MEDIUM',
  `paint_code` VARCHAR(191) NULL,
  `year` INT NULL,
  `vin` VARCHAR(255) NULL,
  `fuel_type` VARCHAR(255) NULL,
  `transmission` VARCHAR(255) NULL,
  `colour` VARCHAR(255) NULL,
  `mileage` INT NULL DEFAULT 0,
  `mot_expiry` VARCHAR(255) NULL,
  `service_due` VARCHAR(255) NULL,
  `notes` LONGTEXT NULL,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_vehicles_customer_id_0` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_vehicles_workshop_id_1` FOREIGN KEY (`workshop_id`) REFERENCES `workshops` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `vehicles`
INSERT INTO `vehicles` (`id`, `workshop_id`, `customer_id`, `registration`, `make`, `model`, `variant`, `vehicle_size`, `paint_code`, `year`, `vin`, `fuel_type`, `transmission`, `colour`, `mileage`, `mot_expiry`, `service_due`, `notes`, `created_at`) VALUES
('veh_16b74473', 'ws_pbs_autos_001', 'cust_eb44f7ea', 'TEST', 'test', 'test', '', 'MEDIUM', NULL, NULL, NULL, NULL, NULL, 'test', 5400, NULL, NULL, NULL, '2026-10-04 00:19:25'),
('veh_0b2853a0', 'ws_pbs_autos_001', 'cust_6b998217', 'GC24 NEW', 'Mercedes-Benz', 'C220d', '', 'MEDIUM', NULL, 2024, NULL, NULL, NULL, 'Silver', 12500, NULL, NULL, NULL, '2026-10-04 00:30:18'),
('veh_30db672e', 'ws_pbs_autos_001', 'cust_3da7ebe9', 'ASD', 'asd', 'asd', '', 'MEDIUM', NULL, NULL, NULL, NULL, NULL, 'asd', 54000, NULL, NULL, NULL, '2026-10-04 00:36:54'),
('veh_96a10fbb', 'ws_pbs_autos_001', 'cust_cec7c839', 'TEST2', 'test2', 'test2', '', 'MEDIUM', NULL, NULL, NULL, NULL, NULL, 'test2', 54000, NULL, NULL, NULL, '2026-10-04 01:02:08'),
('veh_cb0ea1af', 'ws_pbs_autos_001', 'cust_dd362c05', 'TEST3', 'test3', 'test3', '', 'MEDIUM', NULL, NULL, NULL, NULL, NULL, 'test3', 0, NULL, NULL, NULL, '2026-10-04 01:05:01'),
('veh_4e9e6134', 'ws_pbs_autos_001', 'cust_9eca54bc', 'TEST4', 'test4', 'test4', '', 'MEDIUM', NULL, NULL, NULL, NULL, NULL, 'test4', 0, NULL, NULL, NULL, '2026-10-04 01:15:32');

-- --------------------------------------------------------
-- Table structure for table `appointments`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `appointments`;
CREATE TABLE `appointments` (
  `id` VARCHAR(64) NOT NULL,
  `workshop_id` VARCHAR(64) NOT NULL,
  `customer_id` VARCHAR(64) NOT NULL,
  `vehicle_id` VARCHAR(64) NOT NULL,
  `technician_id` VARCHAR(64) NULL,
  `start_time` VARCHAR(255) NOT NULL,
  `duration_mins` INT NOT NULL DEFAULT 60,
  `reason` VARCHAR(255) NOT NULL,
  `status` VARCHAR(191) NOT NULL DEFAULT 'BOOKED',
  `notes` LONGTEXT NULL,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `location` VARCHAR(255) NULL DEFAULT 'YARD',
  `workshop_bay` VARCHAR(255) NULL DEFAULT 'YARD',
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_appointments_technician_id_0` FOREIGN KEY (`technician_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_appointments_vehicle_id_1` FOREIGN KEY (`vehicle_id`) REFERENCES `vehicles` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_appointments_customer_id_2` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_appointments_workshop_id_3` FOREIGN KEY (`workshop_id`) REFERENCES `workshops` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------
-- Table structure for table `jobs`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `jobs`;
CREATE TABLE `jobs` (
  `id` VARCHAR(64) NOT NULL,
  `workshop_id` VARCHAR(64) NOT NULL,
  `job_number` VARCHAR(191) NOT NULL,
  `customer_id` VARCHAR(64) NOT NULL,
  `vehicle_id` VARCHAR(64) NOT NULL,
  `technician_id` VARCHAR(64) NULL,
  `appointment_id` VARCHAR(64) NULL,
  `status` VARCHAR(191) NOT NULL DEFAULT 'BOOKED',
  `workshop_bay` VARCHAR(255) NOT NULL DEFAULT 'BOOKING_IN',
  `job_cost` DECIMAL(12, 2) NOT NULL DEFAULT 0.00,
  `customer_concern` LONGTEXT NOT NULL,
  `accident_damage_description` LONGTEXT NULL,
  `repair_instructions` LONGTEXT NULL,
  `booking_in_date` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `allocated_hours` DECIMAL(12, 2) NULL DEFAULT 3.0,
  `collection_mileage` INT NULL,
  `delivery_mileage` INT NULL,
  `collected_from` VARCHAR(255) NULL,
  `delivered_to` VARCHAR(255) NULL,
  `damage_inspection_json` LONGTEXT NULL,
  `checkin_mileage` INT NULL,
  `vehicle_condition` VARCHAR(255) NULL,
  `estimated_completion` VARCHAR(255) NULL,
  `labour_rate` DECIMAL(12, 2) NOT NULL DEFAULT 85.00,
  `discount_pct` DECIMAL(12, 2) NOT NULL DEFAULT 0.00,
  `vat_pct` DECIMAL(12, 2) NOT NULL DEFAULT 0.00,
  `notes` LONGTEXT NULL,
  `completed_at` VARCHAR(255) NULL,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `trader_id` VARCHAR(64) NULL,
  `customer_type` VARCHAR(255) NULL DEFAULT 'CUSTOMER',
  `vehicle_location` VARCHAR(255) NULL DEFAULT 'YARD',
  `paint_code` VARCHAR(191) NULL DEFAULT '',
  `vehicle_size` VARCHAR(191) NULL DEFAULT 'MEDIUM',
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_jobs_trader_id_0` FOREIGN KEY (`trader_id`) REFERENCES `traders` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_jobs_appointment_id_1` FOREIGN KEY (`appointment_id`) REFERENCES `appointments` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_jobs_technician_id_2` FOREIGN KEY (`technician_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_jobs_vehicle_id_3` FOREIGN KEY (`vehicle_id`) REFERENCES `vehicles` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_jobs_customer_id_4` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_jobs_workshop_id_5` FOREIGN KEY (`workshop_id`) REFERENCES `workshops` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `jobs`
INSERT INTO `jobs` (`id`, `workshop_id`, `job_number`, `customer_id`, `vehicle_id`, `technician_id`, `appointment_id`, `status`, `workshop_bay`, `job_cost`, `customer_concern`, `accident_damage_description`, `repair_instructions`, `booking_in_date`, `allocated_hours`, `collection_mileage`, `delivery_mileage`, `collected_from`, `delivered_to`, `damage_inspection_json`, `checkin_mileage`, `vehicle_condition`, `estimated_completion`, `labour_rate`, `discount_pct`, `vat_pct`, `notes`, `completed_at`, `created_at`, `trader_id`, `customer_type`, `vehicle_location`, `paint_code`, `vehicle_size`) VALUES
('job_2b6bb23f', 'ws_pbs_autos_001', 'JOB-1001', 'cust_eb44f7ea', 'veh_16b74473', 'usr_tech_habibi', NULL, 'COMPLETED', 'COMPLETED', 4000, 'test', 'test', 'test', '2026-10-04', 3, 5400, 5000, 'PBS Autos Bodyshop Intake', 'Customer Address', '{"items":[{"panel_name":"Passenger Front Wing","has_rust":false,"has_scratch":false,"has_dent":true,"description":""}],"photos":[],"collected_from":"PBS Autos Bodyshop Intake","delivered_to":"Customer Address","collection_mileage":5400,"delivery_mileage":5000,"customer_name":"test test","date":"2026-10-04"}', 5400, '', 'test', 85, 0, 0, '', '2026-10-04 00:22:01', '2026-10-04 00:19:25', NULL, 'CUSTOMER', 'BAY', 'test', 'MEDIUM'),
('job_42449e54', 'ws_pbs_autos_001', 'JOB-1002', 'cust_6b998217', 'veh_0b2853a0', NULL, NULL, 'COMPLETED', 'COMPLETED', 0, 'Annual Service & Front Brake Inspection', '', '', '2026-10-04T00:30:18.626Z', 3, NULL, NULL, NULL, NULL, NULL, NULL, '', '2026-10-05T00:30:18.618Z', 85, 0, 0, '', '2026-10-04 00:30:18', '2026-10-04 00:30:18', NULL, 'CUSTOMER', 'YARD', '', 'MEDIUM'),
('job_e8906424', 'ws_pbs_autos_001', 'JOB-1003', 'cust_3da7ebe9', 'veh_30db672e', 'usr_tech_paajii', NULL, 'READY', 'PANEL_PREP_BAY_2', 0, 'test', 'test', 'asd', '2026-10-04', 4, 54000, 54000, 'PBS Autos Bodyshop Intake', 'Customer Address', '{"items":[{"panel_name":"Grille","has_rust":true,"has_scratch":false,"has_dent":false,"description":""}],"photos":[],"collected_from":"PBS Autos Bodyshop Intake","delivered_to":"Customer Address","collection_mileage":54000,"delivery_mileage":54000,"customer_name":"test2 test2","date":"2026-10-04"}', 54000, '', 'Today 17:00', 85, 0, 0, '', NULL, '2026-10-04 00:36:54', NULL, 'CUSTOMER', 'YARD', 'asd', 'MEDIUM'),
('job_ea75c06f', 'ws_pbs_autos_001', 'JOB-1004', 'cust_cec7c839', 'veh_96a10fbb', 'usr_tech_habibi', NULL, 'COMPLETED', 'COMPLETED', 3000, 'test2', 'test2', 'test2', '2026-10-04', 4, 54000, 54000, 'PBS Autos Bodyshop Intake', 'Customer Address', '{"items":[{"panel_name":"Front Bumper","has_rust":true,"has_scratch":false,"has_dent":false,"description":""},{"panel_name":"Passenger Front Door","has_rust":false,"has_scratch":true,"has_dent":false,"description":""}],"photos":[],"collected_from":"PBS Autos Bodyshop Intake","delivered_to":"Customer Address","collection_mileage":54000,"delivery_mileage":54000,"customer_name":"test2 test2","date":"2026-10-04"}', 54000, '', 'Today 17:00', 85, 0, 0, '[Habibi - 06:02]: Completed', '2026-10-04 01:08:05', '2026-10-04 01:02:08', NULL, 'CUSTOMER', 'BAY', 'test2', 'MEDIUM'),
('job_397066f0', 'ws_pbs_autos_001', 'JOB-1005', 'cust_dd362c05', 'veh_cb0ea1af', 'usr_tech_chris', NULL, 'IN_REPAIR', 'PAINT_BOOTH', 3000, 'test3', 'test3', 'test3', '2026-10-04', 3, NULL, NULL, 'PBS Autos Bodyshop Intake', 'Customer Address', '{"items":[{"panel_name":"Passenger Front Wing","has_rust":false,"has_scratch":true,"has_dent":false,"description":""}],"photos":[],"collected_from":"PBS Autos Bodyshop Intake","delivered_to":"Customer Address","customer_name":"test3 test3","date":"2026-10-04"}', NULL, '', 'Today 17:00', 85, 0, 0, '', NULL, '2026-10-04 01:05:01', NULL, 'CUSTOMER', 'BAY', 'test3', 'MEDIUM'),
('job_1cf0a3fa', 'ws_pbs_autos_001', 'JOB-1006', 'cust_9eca54bc', 'veh_4e9e6134', 'usr_tech_chris', NULL, 'IN_REPAIR', 'PAINT_BOOTH', 3000, 'test4', 'test4', 'test4', '2026-10-04', 3, NULL, NULL, 'PBS Autos Bodyshop Intake', 'Customer Address', '{"items":[{"panel_name":"Front Bumper","has_rust":false,"has_scratch":true,"has_dent":false,"description":""}],"photos":[],"collected_from":"PBS Autos Bodyshop Intake","delivered_to":"Customer Address","customer_name":"test4 test4","date":"2026-10-04"}', NULL, '', 'Today 17:00', 85, 0, 0, '', NULL, '2026-10-04 01:15:32', NULL, 'CUSTOMER', 'BAY', 'test4', 'MEDIUM');

-- --------------------------------------------------------
-- Table structure for table `job_labour`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `job_labour`;
CREATE TABLE `job_labour` (
  `id` VARCHAR(64) NOT NULL,
  `job_id` VARCHAR(64) NOT NULL,
  `technician_id` VARCHAR(64) NULL,
  `description` VARCHAR(255) NOT NULL,
  `hours` DECIMAL(12, 2) NOT NULL DEFAULT 0.0,
  `hourly_rate` DECIMAL(12, 2) NOT NULL DEFAULT 85.00,
  `duration_seconds` INT NOT NULL DEFAULT 0,
  `is_active` INT NOT NULL DEFAULT 0,
  `start_time` VARCHAR(255) NULL,
  `end_time` VARCHAR(255) NULL,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_job_labour_technician_id_0` FOREIGN KEY (`technician_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_job_labour_job_id_1` FOREIGN KEY (`job_id`) REFERENCES `jobs` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `job_labour`
INSERT INTO `job_labour` (`id`, `job_id`, `technician_id`, `description`, `hours`, `hourly_rate`, `duration_seconds`, `is_active`, `start_time`, `end_time`, `created_at`) VALUES
('lab_d5babf43', 'job_42449e54', 'usr_admin_001', 'Fitting front brake pads', 5, 85, 18000, 0, '2026-10-04 00:30:18', '2026-10-04 00:30:18', '2026-10-04 00:30:18');

-- --------------------------------------------------------
-- Table structure for table `suppliers`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `suppliers`;
CREATE TABLE `suppliers` (
  `id` VARCHAR(64) NOT NULL,
  `workshop_id` VARCHAR(64) NOT NULL,
  `name` VARCHAR(255) NOT NULL,
  `phone` VARCHAR(191) NULL,
  `email` VARCHAR(191) NULL,
  `contact_person` VARCHAR(255) NULL,
  `notes` LONGTEXT NULL,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_suppliers_workshop_id_0` FOREIGN KEY (`workshop_id`) REFERENCES `workshops` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------
-- Table structure for table `parts`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `parts`;
CREATE TABLE `parts` (
  `id` VARCHAR(64) NOT NULL,
  `workshop_id` VARCHAR(64) NOT NULL,
  `supplier_id` VARCHAR(64) NULL,
  `part_number` VARCHAR(255) NOT NULL,
  `name` VARCHAR(255) NOT NULL,
  `category` VARCHAR(191) NULL,
  `cost_price` DECIMAL(12, 2) NOT NULL DEFAULT 0.0,
  `selling_price` DECIMAL(12, 2) NOT NULL DEFAULT 0.0,
  `stock_quantity` DECIMAL(12, 2) NOT NULL DEFAULT 0.0,
  `min_stock` DECIMAL(12, 2) NOT NULL DEFAULT 0.0,
  `location` VARCHAR(255) NULL,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_parts_supplier_id_0` FOREIGN KEY (`supplier_id`) REFERENCES `suppliers` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_parts_workshop_id_1` FOREIGN KEY (`workshop_id`) REFERENCES `workshops` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------
-- Table structure for table `job_parts`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `job_parts`;
CREATE TABLE `job_parts` (
  `id` VARCHAR(64) NOT NULL,
  `job_id` VARCHAR(64) NOT NULL,
  `part_id` VARCHAR(64) NULL,
  `name` VARCHAR(255) NOT NULL,
  `part_number` VARCHAR(255) NULL,
  `quantity` DECIMAL(12, 2) NOT NULL DEFAULT 1.0,
  `unit_cost` DECIMAL(12, 2) NOT NULL DEFAULT 0.0,
  `unit_price` DECIMAL(12, 2) NOT NULL DEFAULT 0.0,
  `is_inventory_deducted` INT NOT NULL DEFAULT 1,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_job_parts_part_id_0` FOREIGN KEY (`part_id`) REFERENCES `parts` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_job_parts_job_id_1` FOREIGN KEY (`job_id`) REFERENCES `jobs` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------
-- Table structure for table `inspection_templates`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `inspection_templates`;
CREATE TABLE `inspection_templates` (
  `id` VARCHAR(64) NOT NULL,
  `workshop_id` VARCHAR(64) NOT NULL,
  `name` VARCHAR(255) NOT NULL,
  `is_default` INT NOT NULL DEFAULT 0,
  `categories_json` LONGTEXT NOT NULL,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_inspection_templates_workshop_id_0` FOREIGN KEY (`workshop_id`) REFERENCES `workshops` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `inspection_templates`
INSERT INTO `inspection_templates` (`id`, `workshop_id`, `name`, `is_default`, `categories_json`, `created_at`) VALUES
('3a895684-600a-4d8d-b120-4f1b0c8271d0', 'ws_pbs_autos_001', 'Bodyshop Panel & Accident Damage Assessment', 1, '[{"category":"Front End & Structural Subframe","items":["Front Bumper Bar & Valance","Bumper Reinforcer Crossmember","Bonnet Panel Alignment & Gaps","Headlight Tabs & Radiator Core Support","Windscreen Frame & Scuttle Panel"]},{"category":"Nearside Panels (Passenger Side)","items":["Front Left Wing Sheet Metal","Passenger Front Door Skin","Passenger Rear Door Skin","Nearside Sill & Rocker Panel","Left Quarter Panel & Wheel Arch Swage"]},{"category":"Offside Panels (Driver Side)","items":["Front Right Wing Sheet Metal","Driver Front Door Skin","Driver Rear Door Skin","Offside Sill & Rocker Panel","Right Quarter Panel & Wheel Arch Swage"]},{"category":"Rear End & Tailgate Assembly","items":["Rear Bumper & Crash Reinforcer","Tailgate / Boot Lid Alignment","Rear Light Mounting Pockets","Boot Floor & Spare Wheel Well Deformation","Rear Number Plate Surround"]},{"category":"Paint Refinishing & Clearcoat Adhesion","items":["Spectrometer Digital Colour Match","Substrate Feather-Edge Primer Sanding","Basecoat Uniformity & Metal Flake Orientation","2K VOC Clearcoat Gloss & Cure","Orange Peel Match to Factory Finish"]}]', '2026-09-18 14:34:00');

-- --------------------------------------------------------
-- Table structure for table `inspections`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `inspections`;
CREATE TABLE `inspections` (
  `id` VARCHAR(64) NOT NULL,
  `workshop_id` VARCHAR(64) NOT NULL,
  `job_id` VARCHAR(64) NOT NULL,
  `vehicle_id` VARCHAR(64) NOT NULL,
  `technician_id` VARCHAR(64) NULL,
  `status` VARCHAR(191) NOT NULL DEFAULT 'IN_PROGRESS',
  `summary_notes` VARCHAR(255) NULL,
  `share_token` VARCHAR(191) NULL,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_inspections_job_id` (`job_id`),
  UNIQUE KEY `uk_inspections_share_token` (`share_token`),
  CONSTRAINT `fk_inspections_technician_id_0` FOREIGN KEY (`technician_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_inspections_vehicle_id_1` FOREIGN KEY (`vehicle_id`) REFERENCES `vehicles` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_inspections_job_id_2` FOREIGN KEY (`job_id`) REFERENCES `jobs` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_inspections_workshop_id_3` FOREIGN KEY (`workshop_id`) REFERENCES `workshops` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `inspections`
INSERT INTO `inspections` (`id`, `workshop_id`, `job_id`, `vehicle_id`, `technician_id`, `status`, `summary_notes`, `share_token`, `created_at`) VALUES
('insp_495e8323', 'ws_pbs_autos_001', 'job_2b6bb23f', 'veh_16b74473', 'usr_tech_habibi', 'IN_PROGRESS', NULL, 'insp_tok_550edea8-258', '2026-10-04 00:19:25'),
('insp_f3e436e0', 'ws_pbs_autos_001', 'job_42449e54', 'veh_0b2853a0', NULL, 'COMPLETED', 'Brake pads worn down to 2.1mm. Advisories on rear tyre tread depth.', 'insp_tok_9bd424e9-4b6', '2026-10-04 00:30:18'),
('insp_714415ca', 'ws_pbs_autos_001', 'job_e8906424', 'veh_30db672e', 'usr_tech_paajii', 'IN_PROGRESS', NULL, 'insp_tok_b0ab3c26-fb3', '2026-10-04 00:36:54'),
('insp_7419908e', 'ws_pbs_autos_001', 'job_ea75c06f', 'veh_96a10fbb', 'usr_tech_habibi', 'IN_PROGRESS', NULL, 'insp_tok_3316cf21-379', '2026-10-04 01:02:08'),
('insp_23ac783b', 'ws_pbs_autos_001', 'job_397066f0', 'veh_cb0ea1af', 'usr_tech_habibi', 'IN_PROGRESS', NULL, 'insp_tok_07d167a4-648', '2026-10-04 01:05:01'),
('insp_303428d7', 'ws_pbs_autos_001', 'job_1cf0a3fa', 'veh_4e9e6134', 'usr_tech_habibi', 'IN_PROGRESS', NULL, 'insp_tok_a16ea575-b94', '2026-10-04 01:15:32');

-- --------------------------------------------------------
-- Table structure for table `inspection_results`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `inspection_results`;
CREATE TABLE `inspection_results` (
  `id` VARCHAR(64) NOT NULL,
  `inspection_id` VARCHAR(64) NOT NULL,
  `category` VARCHAR(191) NOT NULL,
  `item_name` VARCHAR(255) NOT NULL,
  `condition` VARCHAR(255) NOT NULL,
  `notes` LONGTEXT NULL,
  `measurement` VARCHAR(255) NULL,
  `photos_json` LONGTEXT NULL DEFAULT '[]',
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_inspection_results_inspection_id_0` FOREIGN KEY (`inspection_id`) REFERENCES `inspections` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `inspection_results`
INSERT INTO `inspection_results` (`id`, `inspection_id`, `category`, `item_name`, `condition`, `notes`, `measurement`, `photos_json`, `created_at`) VALUES
('881c43eb-de07-4ad6-89c6-41b0a34489fd', 'insp_f3e436e0', 'Brakes', 'Front Brake Pads', 'URGENT', 'Friction lining worn below 2.5mm minimum legal safety limit.', '2.1mm', '["https://images.unsplash.com/photo-1486006920555-c77dce18193b"]', '2026-10-04 00:30:18'),
('2d8556b6-48e3-4074-ad08-f5b05a75086f', 'insp_f3e436e0', 'Tyres', 'Rear Left Tyre', 'ADVISORY', 'Tread depth close to 2.0mm', '2.4mm', '[]', '2026-10-04 00:30:18'),
('04529f19-e6dc-4796-b7e8-9f18288c6ed9', 'insp_f3e436e0', 'Engine & Fluids', 'Engine Oil Level & Quality', 'GOOD', 'Level topped up with 5W-30 synthetic.', 'Optimal', '[]', '2026-10-04 00:30:18');

-- --------------------------------------------------------
-- Table structure for table `estimates`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `estimates`;
CREATE TABLE `estimates` (
  `id` VARCHAR(64) NOT NULL,
  `workshop_id` VARCHAR(64) NOT NULL,
  `job_id` VARCHAR(64) NOT NULL,
  `estimate_number` VARCHAR(191) NOT NULL,
  `status` VARCHAR(191) NOT NULL DEFAULT 'DRAFT',
  `subtotal` DECIMAL(12, 2) NOT NULL DEFAULT 0.0,
  `discount_amount` DECIMAL(12, 2) NOT NULL DEFAULT 0.0,
  `vat_amount` DECIMAL(12, 2) NOT NULL DEFAULT 0.0,
  `total_amount` DECIMAL(12, 2) NOT NULL DEFAULT 0.0,
  `share_token` VARCHAR(191) NULL,
  `authorized_by_name` VARCHAR(255) NULL,
  `authorized_at` VARCHAR(255) NULL,
  `expires_at` VARCHAR(255) NULL,
  `signature_data` LONGTEXT NULL,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_estimates_share_token` (`share_token`),
  CONSTRAINT `fk_estimates_job_id_0` FOREIGN KEY (`job_id`) REFERENCES `jobs` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_estimates_workshop_id_1` FOREIGN KEY (`workshop_id`) REFERENCES `workshops` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `estimates`
INSERT INTO `estimates` (`id`, `workshop_id`, `job_id`, `estimate_number`, `status`, `subtotal`, `discount_amount`, `vat_amount`, `total_amount`, `share_token`, `authorized_by_name`, `authorized_at`, `expires_at`, `signature_data`, `created_at`) VALUES
('est_e4343ab6', 'ws_pbs_autos_001', 'job_42449e54', 'EST-1001', 'DRAFT', 300, 0, 60, 360, 'appr_f53d48d0-f38c-46', NULL, NULL, '2026-10-18', NULL, '2026-10-04 00:30:18');

-- --------------------------------------------------------
-- Table structure for table `estimate_items`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `estimate_items`;
CREATE TABLE `estimate_items` (
  `id` VARCHAR(64) NOT NULL,
  `estimate_id` VARCHAR(64) NOT NULL,
  `type` VARCHAR(191) NOT NULL DEFAULT 'LABOUR',
  `description` VARCHAR(255) NOT NULL,
  `quantity_hours` DECIMAL(12, 2) NOT NULL DEFAULT 1.0,
  `unit_price_rate` DECIMAL(12, 2) NOT NULL DEFAULT 0.0,
  `total_amount` DECIMAL(12, 2) NOT NULL DEFAULT 0.0,
  `status` VARCHAR(191) NOT NULL DEFAULT 'PENDING',
  `is_approved` INT NULL,
  `source_inspection_result_id` VARCHAR(64) NULL,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_estimate_items_estimate_id_0` FOREIGN KEY (`estimate_id`) REFERENCES `estimates` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `estimate_items`
INSERT INTO `estimate_items` (`id`, `estimate_id`, `type`, `description`, `quantity_hours`, `unit_price_rate`, `total_amount`, `status`, `is_approved`, `source_inspection_result_id`, `created_at`) VALUES
('44bac0fb-1286-4ac7-aab7-6195348a4b55', 'est_e4343ab6', 'LABOUR', 'Labour: Front Brake Pads repair / replacement', 1, 85, 85, 'PENDING', NULL, '881c43eb-de07-4ad6-89c6-41b0a34489fd', '2026-10-04 00:30:18'),
('cad23191-e3ec-41ee-be5b-56bf79b2e5a6', 'est_e4343ab6', 'PART', 'Required parts for Front Brake Pads', 1, 65, 65, 'PENDING', NULL, '881c43eb-de07-4ad6-89c6-41b0a34489fd', '2026-10-04 00:30:18'),
('d31b3311-4d21-41ad-88a1-4ccbf23234ea', 'est_e4343ab6', 'LABOUR', 'Labour: Rear Left Tyre repair / replacement', 1, 85, 85, 'PENDING', NULL, '2d8556b6-48e3-4074-ad08-f5b05a75086f', '2026-10-04 00:30:18'),
('47edb339-dd46-43c8-9503-e3f50b1243c8', 'est_e4343ab6', 'PART', 'Required parts for Rear Left Tyre', 1, 65, 65, 'PENDING', NULL, '2d8556b6-48e3-4074-ad08-f5b05a75086f', '2026-10-04 00:30:18');

-- --------------------------------------------------------
-- Table structure for table `quality_checks`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `quality_checks`;
CREATE TABLE `quality_checks` (
  `id` VARCHAR(64) NOT NULL,
  `job_id` VARCHAR(64) NOT NULL,
  `technician_id` VARCHAR(64) NULL,
  `items_json` LONGTEXT NOT NULL,
  `passed` INT NOT NULL DEFAULT 0,
  `completed_by` VARCHAR(255) NULL,
  `notes` LONGTEXT NULL,
  `signed_at` VARCHAR(255) NULL,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_quality_checks_job_id` (`job_id`),
  CONSTRAINT `fk_quality_checks_technician_id_0` FOREIGN KEY (`technician_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_quality_checks_job_id_1` FOREIGN KEY (`job_id`) REFERENCES `jobs` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `quality_checks`
INSERT INTO `quality_checks` (`id`, `job_id`, `technician_id`, `items_json`, `passed`, `completed_by`, `notes`, `signed_at`, `created_at`) VALUES
('664a0a1a-f57e-4bd6-91d2-8930f3a37b45', 'job_42449e54', NULL, '{"road_test":true,"wheel_nuts_torqued":true,"fluid_levels_checked":true,"service_light_reset":true,"vehicle_cleaned":true}', 1, 'PBS Autos Admin', 'Road test 3.5 miles completed. Brakes bedded in smoothly.', NULL, '2026-10-04 00:30:18');

-- --------------------------------------------------------
-- Table structure for table `invoices`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `invoices`;
CREATE TABLE `invoices` (
  `id` VARCHAR(64) NOT NULL,
  `workshop_id` VARCHAR(64) NOT NULL,
  `job_id` VARCHAR(64) NOT NULL,
  `customer_id` VARCHAR(64) NOT NULL,
  `vehicle_id` VARCHAR(64) NULL,
  `invoice_number` VARCHAR(191) NOT NULL,
  `status` VARCHAR(191) NOT NULL DEFAULT 'SENT',
  `issue_date` VARCHAR(255) NOT NULL,
  `due_date` VARCHAR(255) NOT NULL,
  `subtotal` DECIMAL(12, 2) NOT NULL DEFAULT 0.0,
  `discount_amount` DECIMAL(12, 2) NOT NULL DEFAULT 0.0,
  `vat_amount` DECIMAL(12, 2) NOT NULL DEFAULT 0.0,
  `total_amount` DECIMAL(12, 2) NOT NULL DEFAULT 0.0,
  `paid_amount` DECIMAL(12, 2) NOT NULL DEFAULT 0.0,
  `balance_due` DECIMAL(12, 2) NOT NULL DEFAULT 0.0,
  `share_token` VARCHAR(191) NULL,
  `notes` LONGTEXT NULL,
  `payment_terms` VARCHAR(255) NULL DEFAULT 'Payment due upon collection of vehicle.',
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_invoices_share_token` (`share_token`),
  CONSTRAINT `fk_invoices_vehicle_id_0` FOREIGN KEY (`vehicle_id`) REFERENCES `vehicles` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_invoices_customer_id_1` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_invoices_job_id_2` FOREIGN KEY (`job_id`) REFERENCES `jobs` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_invoices_workshop_id_3` FOREIGN KEY (`workshop_id`) REFERENCES `workshops` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `invoices`
INSERT INTO `invoices` (`id`, `workshop_id`, `job_id`, `customer_id`, `vehicle_id`, `invoice_number`, `status`, `issue_date`, `due_date`, `subtotal`, `discount_amount`, `vat_amount`, `total_amount`, `paid_amount`, `balance_due`, `share_token`, `notes`, `payment_terms`, `created_at`) VALUES
('inv_aed3e3ab', 'ws_pbs_autos_001', 'job_2b6bb23f', 'cust_eb44f7ea', 'veh_16b74473', 'PBS-1001', 'PAID', '2026-10-04', '2026-10-04', 4000, 0, 0, 4000, 4000, 0, 'tok_c9c01424-97b0-41', NULL, 'Due upon collection', '2026-10-04 00:21:47'),
('inv_c788c60a', 'ws_pbs_autos_001', 'job_42449e54', 'cust_6b998217', 'veh_0b2853a0', 'PBS-1002', 'SENT', '2026-10-04', '2026-10-04', 4000, 0, 800, 4800, 0, 4800, 'tok_0d0f802c-c04e-4c', NULL, 'Due upon collection', '2026-10-04 00:30:18'),
('inv_247a20a0', 'ws_pbs_autos_001', 'job_42449e54', 'cust_6b998217', 'veh_0b2853a0', 'PBS-1003', 'PAID', '2026-10-04', '2026-10-11', 425, 0, 0, 425, 425, 0, 'inv_tok_6067344f-b7d1-4b', NULL, 'Due upon collection', '2026-10-04 00:30:18'),
('inv_8d62be09', 'ws_pbs_autos_001', 'job_e8906424', 'cust_3da7ebe9', 'veh_30db672e', 'PBS-1004', 'PAID', '2026-10-04', '2026-10-04', 0, 0, 0, 0, 0, 0, 'tok_ff979888-f61d-46', NULL, 'Due upon collection', '2026-10-04 00:42:26'),
('inv_0146a628', 'ws_pbs_autos_001', 'job_2b6bb23f', 'cust_eb44f7ea', 'veh_16b74473', 'PBS-1005', 'SENT', '2026-10-04', '2026-10-11', 4000, 0, 0, 4000, 0, 4000, 'inv_tok_7e665cb4-b817-45', NULL, 'Due upon collection', '2026-10-04 00:45:05'),
('inv_dbaefcf8', 'ws_pbs_autos_001', 'job_ea75c06f', 'cust_cec7c839', 'veh_96a10fbb', 'PBS-1006', 'PAID', '2026-10-04', '2026-10-04', 3000, 0, 0, 3000, 3000, 0, 'tok_7a316686-9e5e-46', NULL, 'Due upon collection', '2026-10-04 01:07:32');

-- --------------------------------------------------------
-- Table structure for table `invoice_items`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `invoice_items`;
CREATE TABLE `invoice_items` (
  `id` VARCHAR(64) NOT NULL,
  `invoice_id` VARCHAR(64) NOT NULL,
  `type` VARCHAR(191) NULL DEFAULT 'LABOUR',
  `item_type` VARCHAR(255) NULL DEFAULT 'LABOUR',
  `description` VARCHAR(255) NOT NULL,
  `quantity` DECIMAL(12, 2) NOT NULL DEFAULT 1.0,
  `quantity_hours` DECIMAL(12, 2) NOT NULL DEFAULT 1.0,
  `unit_price` DECIMAL(12, 2) NOT NULL DEFAULT 0.0,
  `unit_price_rate` DECIMAL(12, 2) NOT NULL DEFAULT 0.0,
  `total_amount` DECIMAL(12, 2) NOT NULL DEFAULT 0.0,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_invoice_items_invoice_id_0` FOREIGN KEY (`invoice_id`) REFERENCES `invoices` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `invoice_items`
INSERT INTO `invoice_items` (`id`, `invoice_id`, `type`, `item_type`, `description`, `quantity`, `quantity_hours`, `unit_price`, `unit_price_rate`, `total_amount`, `created_at`) VALUES
('54a55bf0-5d32-4744-b9b5-1b8dbc8a7389', 'inv_aed3e3ab', 'LABOUR', 'LABOUR', 'test', 1, 1, 4000, 0, 4000, '2026-10-04 00:21:47'),
('a2ef87fe-c7a4-4cad-908c-4995eef204bb', 'inv_247a20a0', 'LABOUR', 'LABOUR', 'Fitting front brake pads', 5, 1, 85, 0, 425, '2026-10-04 00:30:18'),
('11361a52-f160-4365-8635-adce42db5e20', 'inv_8d62be09', 'LABOUR', 'LABOUR', 'test', 1, 1, 0, 0, 0, '2026-10-04 00:44:15'),
('d5b1276b-cc4d-436e-a4dc-49f15a47d855', 'inv_0146a628', 'LABOUR', 'LABOUR', 'Agreed Bodyshop Fixed Repair: test', 1, 1, 4000, 0, 4000, '2026-10-04 00:45:05'),
('0450b20f-ccff-474d-b851-d82e3cda0e9c', 'inv_c788c60a', 'LABOUR', 'SUBLET', 'ASSINGMENT', 1, 1, 4000, 0, 4000, '2026-10-04 00:45:51'),
('bfe56db3-fb36-4601-9755-39aac3cc0dc2', 'inv_dbaefcf8', 'LABOUR', 'LABOUR', 'test2', 1, 1, 3000, 0, 3000, '2026-10-04 01:07:32');

-- --------------------------------------------------------
-- Table structure for table `payments`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `payments`;
CREATE TABLE `payments` (
  `id` VARCHAR(64) NOT NULL,
  `workshop_id` VARCHAR(64) NOT NULL,
  `invoice_id` VARCHAR(64) NOT NULL,
  `customer_id` VARCHAR(64) NOT NULL,
  `amount` DECIMAL(12, 2) NOT NULL,
  `payment_method` VARCHAR(255) NOT NULL,
  `reference` VARCHAR(255) NULL,
  `notes` LONGTEXT NULL,
  `payment_date` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `paid_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_payments_customer_id_0` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_payments_invoice_id_1` FOREIGN KEY (`invoice_id`) REFERENCES `invoices` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_payments_workshop_id_2` FOREIGN KEY (`workshop_id`) REFERENCES `workshops` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `payments`
INSERT INTO `payments` (`id`, `workshop_id`, `invoice_id`, `customer_id`, `amount`, `payment_method`, `reference`, `notes`, `payment_date`, `paid_at`, `created_at`) VALUES
('pay_bfc23c07', 'ws_pbs_autos_001', 'inv_aed3e3ab', 'cust_eb44f7ea', 4000, 'CASH', '', 'Cash', '2026-10-04 00:22:01', '2026-10-04 00:22:01', '2026-10-04 00:22:01'),
('pay_56bc0af9', 'ws_pbs_autos_001', 'inv_247a20a0', 'cust_6b998217', 425, 'CARD', 'Barclaycard auth #99214', '', '2026-10-04 00:30:18', '2026-10-04 00:30:18', '2026-10-04 00:30:18'),
('pay_d48ca905', 'ws_pbs_autos_001', 'inv_dbaefcf8', 'cust_cec7c839', 3000, 'CASH', '', 'TAST', '2026-10-04 01:08:05', '2026-10-04 01:08:05', '2026-10-04 01:08:05');

-- --------------------------------------------------------
-- Table structure for table `messages`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `messages`;
CREATE TABLE `messages` (
  `id` VARCHAR(64) NOT NULL,
  `workshop_id` VARCHAR(64) NOT NULL,
  `customer_id` VARCHAR(64) NOT NULL,
  `job_id` VARCHAR(64) NULL,
  `direction` VARCHAR(191) NOT NULL,
  `channel` VARCHAR(191) NOT NULL,
  `sender` VARCHAR(255) NOT NULL,
  `recipient` VARCHAR(255) NOT NULL,
  `subject` VARCHAR(255) NULL,
  `body` LONGTEXT NOT NULL,
  `status` VARCHAR(191) NOT NULL DEFAULT 'SENT',
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_messages_job_id_0` FOREIGN KEY (`job_id`) REFERENCES `jobs` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_messages_customer_id_1` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_messages_workshop_id_2` FOREIGN KEY (`workshop_id`) REFERENCES `workshops` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `messages`
INSERT INTO `messages` (`id`, `workshop_id`, `customer_id`, `job_id`, `direction`, `channel`, `sender`, `recipient`, `subject`, `body`, `status`, `created_at`) VALUES
('33377a6a-f0d5-4dfb-9cf4-6985e545242c', 'ws_pbs_autos_001', 'cust_eb44f7ea', 'job_2b6bb23f', 'OUTBOUND', 'WHATSAPP', 'PBS Autos — Body Panel & Accident Damage Repairs', '0342847983', NULL, 'Great news, test test!\n\nYour test test (TEST) has completed final paint curing and bodyshop quality inspection at PBS Autos — Body Panel & Accident Damage Repairs.\n\nTotal due: £4000.00\nView your VAT invoice & pay online: http://localhost:5000/invoice/tok_c9c01424-97b0-41\n\nWe look forward to presenting your vehicle!', 'DELIVERED', '2026-10-04 00:21:47'),
('c1f0bb98-f211-43a3-a8dc-bfb38fa8aad1', 'ws_pbs_autos_001', 'cust_6b998217', 'job_42449e54', 'OUTBOUND', 'WHATSAPP', 'PBS Autos — Body Panel & Accident Damage Repairs', '07700900999', NULL, 'Great news, George Clark!\n\nYour Mercedes-Benz C220d (GC24 NEW) has completed final paint curing and bodyshop quality inspection at PBS Autos — Body Panel & Accident Damage Repairs.\n\nTotal due: £0.00\nView your VAT invoice & pay online: https://localhost:5000/invoice/tok_0d0f802c-c04e-4c\n\nWe look forward to presenting your vehicle!', 'DELIVERED', '2026-10-04 00:30:18'),
('ed18494b-e48c-4278-89b4-75a50938cb84', 'ws_pbs_autos_001', 'cust_3da7ebe9', 'job_e8906424', 'OUTBOUND', 'WHATSAPP', 'PBS Autos — Body Panel & Accident Damage Repairs', '0324304993', NULL, 'Great news, test2 test2!\n\nYour asd asd (ASD) has completed final paint curing and bodyshop quality inspection at PBS Autos — Body Panel & Accident Damage Repairs.\n\nTotal due: £0.00\nView your VAT invoice & pay online: http://localhost:5000/invoice/tok_ff979888-f61d-46\n\nWe look forward to presenting your vehicle!', 'DELIVERED', '2026-10-04 00:42:26'),
('595db977-e74c-488c-b5d1-d865acce4ef7', 'ws_pbs_autos_001', 'cust_3da7ebe9', 'job_e8906424', 'OUTBOUND', 'WHATSAPP', 'PBS Autos — Body Panel & Accident Damage Repairs', '0324304993', NULL, 'Hello test2,\n\nYour invoice PBS-1004 for asd asd (ASD) is ready.\n\nTotal: £0.00\nBalance Due: £0.00\n\nView invoice & pay online: http://localhost:5000/invoice/tok_ff979888-f61d-46\n\nPBS Autos — Body Repairs & Detailing.', 'DELIVERED', '2026-10-04 00:42:38'),
('77d624c5-11a8-4d1a-902a-08aafc871160', 'ws_pbs_autos_001', 'cust_3da7ebe9', 'job_e8906424', 'OUTBOUND', 'WHATSAPP', 'PBS Autos — Body Panel & Accident Damage Repairs', '0324304993', NULL, 'Hello test2,\n\nYour invoice PBS-1004 for asd asd (ASD) is ready.\n\nTotal: £0.00\nBalance Due: £0.00\n\nView invoice & pay online: http://localhost:5000/invoice/tok_ff979888-f61d-46\n\nPBS Autos — Body Repairs & Detailing.', 'DELIVERED', '2026-10-04 00:42:42'),
('383f7f6d-440b-4842-b7db-59a5bf17aebc', 'ws_pbs_autos_001', 'cust_3da7ebe9', 'job_e8906424', 'OUTBOUND', 'WHATSAPP', 'PBS Autos — Body Panel & Accident Damage Repairs', '0324304993', NULL, 'Hello test2,\n\nYour invoice PBS-1004 for asd asd (ASD) is ready.\n\nTotal: £0.00\nBalance Due: £0.00\n\nView invoice & pay online: http://localhost:5000/invoice/tok_ff979888-f61d-46\n\nPBS Autos — Body Repairs & Detailing.', 'DELIVERED', '2026-10-04 00:42:56'),
('c7adb3dd-bbb7-4d4a-a090-c7af6a336f63', 'ws_pbs_autos_001', 'cust_cec7c839', 'job_ea75c06f', 'OUTBOUND', 'WHATSAPP', 'PBS Autos — Body Panel & Accident Damage Repairs', '03425430094', NULL, 'Great news, test2 test2!\n\nYour test2 test2 (TEST2) has completed final paint curing and bodyshop quality inspection at PBS Autos — Body Panel & Accident Damage Repairs.\n\nTotal due: £3000.00\nView your VAT invoice & pay online: http://localhost:5000/invoice/tok_7a316686-9e5e-46\n\nWe look forward to presenting your vehicle!', 'DELIVERED', '2026-10-04 01:07:32'),
('d7298ace-c6e4-4b5a-9992-37340a0295ee', 'ws_pbs_autos_001', 'cust_cec7c839', 'job_ea75c06f', 'OUTBOUND', 'WHATSAPP', 'PBS Autos — Body Panel & Accident Damage Repairs', '03425430094', NULL, 'Hello test2,\n\nYour invoice PBS-1006 for test2 test2 (TEST2) is ready.\n\nTotal: £3000.00\nBalance Due: £3000.00\n\nView invoice & pay online: http://localhost:5000/invoice/tok_7a316686-9e5e-46\n\nPBS Autos — Body Repairs & Detailing.', 'DELIVERED', '2026-10-04 01:07:38'),
('5e7c93ee-2872-4188-a0bf-277ed9f5983b', 'ws_pbs_autos_001', 'cust_cec7c839', 'job_ea75c06f', 'OUTBOUND', 'WHATSAPP', 'PBS Autos — Body Panel & Accident Damage Repairs', '03425430094', NULL, 'Hello test2,\n\nYour invoice PBS-1006 for test2 test2 (TEST2) is ready.\n\nTotal: £3000.00\nBalance Due: £0.00\n\nView invoice & pay online: http://localhost:5000/invoice/tok_7a316686-9e5e-46\n\nPBS Autos — Body Repairs & Detailing.', 'DELIVERED', '2026-10-04 01:08:23');

-- --------------------------------------------------------
-- Table structure for table `message_templates`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `message_templates`;
CREATE TABLE `message_templates` (
  `id` VARCHAR(64) NOT NULL,
  `workshop_id` VARCHAR(64) NOT NULL,
  `channel` VARCHAR(191) NOT NULL,
  `event_trigger` VARCHAR(255) NOT NULL,
  `name` VARCHAR(255) NOT NULL,
  `subject` VARCHAR(255) NULL,
  `body_template` VARCHAR(255) NOT NULL,
  `is_active` INT NOT NULL DEFAULT 1,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_message_templates_workshop_id_0` FOREIGN KEY (`workshop_id`) REFERENCES `workshops` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `message_templates`
INSERT INTO `message_templates` (`id`, `workshop_id`, `channel`, `event_trigger`, `name`, `subject`, `body_template`, `is_active`, `created_at`) VALUES
('f110b91b-8b40-432e-88bb-0974656a3b13', 'ws_pbs_autos_001', 'WHATSAPP', 'INSPECTION_READY', 'Accident Damage Assessment Complete - WhatsApp', NULL, 'Hello {{customer_name}},\n\nYour vehicle panel inspection & repair assessment for {{vehicle_reg}} is now complete.\n\nView your 360 digital report with high-res photos and repair recommendations:\n{{inspection_link}}\n\nKind regards,\n{{workshop_name}}', 1, '2026-09-18 14:34:00'),
('9ddd349a-5c92-4c59-8cf8-8029ad0d72bf', 'ws_pbs_autos_001', 'WHATSAPP', 'ESTIMATE_APPROVAL', 'Bodyshop Repair Estimate - WhatsApp', NULL, 'Hello {{customer_name}},\n\nWe have prepared the itemised body repair estimate for {{vehicle_reg}} totalling £{{total_amount}} (Inc. VAT).\n\nPlease review the panel repairs and paint refinishing specification here:\n{{approval_link}}\n\nThank you,\n{{workshop_name}}', 1, '2026-09-18 14:34:00'),
('89410938-ea9e-4894-8c5f-c9778b863107', 'ws_pbs_autos_001', 'WHATSAPP', 'VEHICLE_READY', 'Vehicle Ready for Handover - WhatsApp', NULL, 'Great news, {{customer_name}}!\n\nYour {{vehicle_make}} {{vehicle_model}} ({{vehicle_reg}}) has completed final paint curing and bodyshop quality inspection at {{workshop_name}}.\n\nTotal due: £{{balance_due}}\nView your VAT invoice & pay online: {{invoice_link}}\n\nWe look forward to presenting your vehicle!', 1, '2026-09-18 14:34:00'),
('fb5a45aa-eed9-4a2e-9e0b-e11e221879dd', 'ws_pbs_autos_001', 'EMAIL', 'ESTIMATE_APPROVAL', 'Bodyshop Repair Estimate - Email', 'Bodyshop Repair Estimate for {{vehicle_reg}} - {{workshop_name}}', '<p>Dear {{customer_name}},</p><p>Thank you for trusting {{workshop_name}}. Our repair estimators have completed the assessment on your <strong>{{vehicle_make}} {{vehicle_model}} ({{vehicle_reg}})</strong>.</p><p><strong>Estimate Total: £{{total_amount}} (Inc. UK VAT)</strong></p><p><a href="{{approval_link}}" style="background:#0284c7;color:#ffffff;padding:12px 20px;text-decoration:none;border-radius:6px;display:inline-block;font-weight:bold;">Review & Authorise Bodyshop Work</a></p><p>Kind regards,<br>{{workshop_name}}<br>{{workshop_phone}}</p>', 1, '2026-09-18 14:34:00');

-- --------------------------------------------------------
-- Table structure for table `reminders`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `reminders`;
CREATE TABLE `reminders` (
  `id` VARCHAR(64) NOT NULL,
  `workshop_id` VARCHAR(64) NOT NULL,
  `customer_id` VARCHAR(64) NOT NULL,
  `vehicle_id` VARCHAR(64) NOT NULL,
  `type` VARCHAR(191) NOT NULL,
  `due_date` VARCHAR(255) NOT NULL,
  `status` VARCHAR(191) NOT NULL DEFAULT 'PENDING',
  `notes` LONGTEXT NULL,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_reminders_vehicle_id_0` FOREIGN KEY (`vehicle_id`) REFERENCES `vehicles` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_reminders_customer_id_1` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_reminders_workshop_id_2` FOREIGN KEY (`workshop_id`) REFERENCES `workshops` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------
-- Table structure for table `inventory_transactions`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `inventory_transactions`;
CREATE TABLE `inventory_transactions` (
  `id` VARCHAR(64) NOT NULL,
  `part_id` VARCHAR(64) NOT NULL,
  `job_id` VARCHAR(64) NULL,
  `type` VARCHAR(191) NOT NULL,
  `quantity` DECIMAL(12, 2) NOT NULL,
  `unit_price` DECIMAL(12, 2) NOT NULL,
  `notes` LONGTEXT NULL,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_inventory_transactions_job_id_0` FOREIGN KEY (`job_id`) REFERENCES `jobs` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_inventory_transactions_part_id_1` FOREIGN KEY (`part_id`) REFERENCES `parts` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------
-- Table structure for table `job_status_history`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `job_status_history`;
CREATE TABLE `job_status_history` (
  `id` VARCHAR(64) NOT NULL,
  `job_id` VARCHAR(64) NOT NULL,
  `from_status` VARCHAR(255) NULL,
  `to_status` VARCHAR(255) NOT NULL,
  `changed_by` VARCHAR(255) NULL,
  `notes` LONGTEXT NULL,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_job_status_history_job_id_0` FOREIGN KEY (`job_id`) REFERENCES `jobs` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `job_status_history`
INSERT INTO `job_status_history` (`id`, `job_id`, `from_status`, `to_status`, `changed_by`, `notes`, `created_at`) VALUES
('d5848a73-8572-45a4-8dfb-07bde6d5de08', 'job_2b6bb23f', NULL, 'CHECKED_IN', 'PBS Autos Admin', 'Job created via Bodyshop Intake Wizard', '2026-10-04 00:19:25'),
('28cb61da-e85c-4e30-b7c1-6e1fc09c7c2c', 'job_2b6bb23f', 'CHECKED_IN', 'IN_REPAIR', 'PBS Autos Admin', 'Stage 3 completed: Allocated to bay_1 (3 hrs)', '2026-10-04 00:19:50'),
('16d0456f-b606-4bf4-a7b9-a523d3eab313', 'job_2b6bb23f', 'IN_REPAIR', 'IN_REPAIR', 'PBS Autos Admin', 'Stage 3 completed: Allocated to bay_1 (3 hrs)', '2026-10-04 00:20:14'),
('1a332b16-da8d-48e6-b3d5-65240058b03c', 'job_2b6bb23f', 'IN_REPAIR', 'IN_REPAIR', 'PBS Autos Admin', 'Stage 3 completed: Allocated to bay_1 (3 hrs)', '2026-10-04 00:20:51'),
('cf85ce2c-c412-460c-82af-4936c7b22d2a', 'job_2b6bb23f', 'bay_1', 'bay_1', 'PBS Autos Admin', 'Assigned from Holding Yard to bay 1', '2026-10-04 00:21:11'),
('99b94024-cee1-43d3-845f-cc7a4e0a8f08', 'job_2b6bb23f', 'IN_REPAIR', 'READY', 'PBS Autos Admin', 'Moved to READY', '2026-10-04 00:21:47'),
('5f2b76cf-a25d-4354-83fd-16e4fe4ad1c6', 'job_2b6bb23f', 'READY', 'COMPLETED', 'PBS Autos Admin', 'Payment received in full and vehicle collected', '2026-10-04 00:22:01'),
('3932db92-1322-4cad-b6ea-af05b2c39821', 'job_42449e54', NULL, 'CHECKED_IN', 'PBS Autos Admin', 'Job created via Bodyshop Intake Wizard', '2026-10-04 00:30:18'),
('333fb69c-dd27-47d4-bc22-f146c1178369', 'job_42449e54', 'CHECKED_IN', 'IN_REPAIR', 'PBS Autos Admin', 'Moved to IN_REPAIR', '2026-10-04 00:30:18'),
('e4c0845d-fef2-41d5-bd38-88f79142af8b', 'job_42449e54', 'QUALITY_CHECK', 'READY', 'PBS Autos Admin', 'Quality control checklist passed', '2026-10-04 00:30:18'),
('9d802478-3aca-402c-833d-1888d02ed2e6', 'job_42449e54', 'READY', 'READY', 'PBS Autos Admin', 'Moved to READY', '2026-10-04 00:30:18'),
('4084bf9f-2962-4163-ba0d-33ac0c88bf06', 'job_42449e54', 'READY', 'COMPLETED', 'PBS Autos Admin', 'Payment received in full and vehicle collected', '2026-10-04 00:30:18'),
('780aa27a-985e-4ffc-bbd3-8c590e12751b', 'job_e8906424', NULL, 'CHECKED_IN', 'PBS Autos Admin', 'Job created via Bodyshop Intake Wizard', '2026-10-04 00:36:54'),
('b2bd6bb3-3218-46bb-bee6-b62b4a1ec3d7', 'job_e8906424', 'CHECKED_IN', 'IN_REPAIR', 'PBS Autos Admin', 'Stage 3 completed: Allocated to bay_1 (3 hrs)', '2026-10-04 00:37:06'),
('117ddd3b-2594-494e-9385-42a0b66aab11', 'job_e8906424', 'IN_REPAIR', 'IN_REPAIR', 'PBS Autos Admin', 'Stage 3 completed: Allocated to bay_1 (4 hrs)', '2026-10-04 00:41:16'),
('9378083c-5033-4ee3-8d3b-bfc096127cc5', 'job_e8906424', 'IN_REPAIR', 'IN_REPAIR', 'PBS Autos Admin', 'Stage 3 completed: Allocated to bay_1 (4 hrs)', '2026-10-04 00:41:35'),
('10c95568-09e4-4018-a673-56bea7e0cf8a', 'job_e8906424', 'IN_REPAIR', 'IN_REPAIR', 'PBS Autos Admin', 'Stage 3 completed: Allocated to bay_2 (4 hrs)', '2026-10-04 00:42:21'),
('a3b1f583-246e-4077-976e-f3dc29651a45', 'job_e8906424', 'IN_REPAIR', 'READY', 'PBS Autos Admin', 'Moved to READY', '2026-10-04 00:42:26'),
('3b6af7d7-2188-4253-8465-d1314900ee4a', 'job_ea75c06f', NULL, 'CHECKED_IN', 'PBS Autos Admin', 'Job created via Bodyshop Intake Wizard', '2026-10-04 01:02:08'),
('b0d2d69e-0487-459a-9e5f-97ddf61d5794', 'job_ea75c06f', 'CHECKED_IN', 'IN_REPAIR', 'PBS Autos Admin', 'Stage 3 completed: Allocated to bay_1 (4 hrs)', '2026-10-04 01:02:22'),
('234a39f2-90fe-47f5-b521-e21a23056bac', 'job_397066f0', NULL, 'IN_REPAIR', 'PBS Autos Admin', 'Job created via Bodyshop Intake Wizard', '2026-10-04 01:05:01'),
('f22b1f60-e380-47ed-ae15-6cb84183550f', 'job_ea75c06f', 'bay_1', 'PANEL_PREP_BAY_2', 'PBS Autos Admin', 'Bay stage moved to PANEL PREP BAY 2', '2026-10-04 01:06:22'),
('b0559502-af21-499b-baf8-bd1f31c52f2a', 'job_ea75c06f', 'PANEL_PREP_BAY_2', 'PANEL_PREP_BAY_1', 'PBS Autos Admin', 'Bay stage moved to PANEL PREP BAY 1', '2026-10-04 01:06:28'),
('284bd8c9-ea1e-4574-8374-76a916c3b940', 'job_ea75c06f', 'IN_REPAIR', 'READY', 'PBS Autos Admin', 'Moved to READY', '2026-10-04 01:07:32'),
('442e4ad1-3004-4f3c-b75e-abf0611577fa', 'job_ea75c06f', 'READY', 'COMPLETED', 'PBS Autos Admin', 'Payment received in full and vehicle collected', '2026-10-04 01:08:05'),
('e1853438-e8fe-4eb0-9bc1-49427d7f7bb2', 'job_1cf0a3fa', NULL, 'CHECKED_IN', 'PBS Autos Admin', 'Job created via Bodyshop Intake Wizard', '2026-10-04 01:15:32'),
('a10d81d0-07aa-4df3-a989-03d162098d38', 'job_1cf0a3fa', 'CHECKED_IN', 'IN_REPAIR', 'PBS Autos Admin', 'Stage 3 completed: Allocated to PANEL_PREP_BAY_1 (3 hrs)', '2026-10-04 01:15:46'),
('7c128fdc-ac75-4832-8858-ad5cf953f756', 'job_1cf0a3fa', 'PANEL_PREP_BAY_1', 'PAINT_BOOTH', 'Habibi', 'Prep task completed in Bay 1 by Habibi. Vehicle moved to Sprayer 1 (Paint Booth).', '2026-10-04 01:16:14'),
('515272bd-867c-4ba7-acde-a0d0c0059df2', 'job_397066f0', 'PANEL_PREP_BAY_1', 'PAINT_BOOTH', 'Habibi', 'Prep task completed in Bay 1 by Habibi. Vehicle moved to Sprayer 1 (Paint Booth).', '2026-10-04 01:16:20');

-- --------------------------------------------------------
-- Table structure for table `notifications`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `notifications`;
CREATE TABLE `notifications` (
  `id` VARCHAR(64) NOT NULL,
  `workshop_id` VARCHAR(64) NOT NULL,
  `user_id` VARCHAR(64) NOT NULL,
  `job_id` VARCHAR(64) NULL,
  `type` VARCHAR(191) NOT NULL,
  `title` VARCHAR(255) NOT NULL,
  `message` VARCHAR(255) NOT NULL,
  `is_read` INT NOT NULL DEFAULT 0,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_notifications_job_id_0` FOREIGN KEY (`job_id`) REFERENCES `jobs` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_notifications_user_id_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_notifications_workshop_id_2` FOREIGN KEY (`workshop_id`) REFERENCES `workshops` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `notifications`
INSERT INTO `notifications` (`id`, `workshop_id`, `user_id`, `job_id`, `type`, `title`, `message`, `is_read`, `created_at`) VALUES
('fc914b78-5b0d-45b6-b113-648121131103', 'ws_pbs_autos_001', 'usr_tech_habibi', 'job_2b6bb23f', 'BAY_ASSIGNED', '🚗 New Job in bay 1: test test (TEST) (3 hrs)', 'Admin completed Scope & Pricing for test test (TEST). Allocated to bay 1 (3 hrs). Price: £4000.00. Scope: test. Damage: test. Please take the car and start working on it.', 0, '2026-10-04 00:19:50'),
('2f18d978-4b94-45a7-a3dd-42e8c9c7371f', 'ws_pbs_autos_001', 'usr_tech_habibi', 'job_2b6bb23f', 'BAY_ASSIGNED', '🚗 New Job in bay 1: test test (TEST) (3 hrs)', 'Admin completed Scope & Pricing for test test (TEST). Allocated to bay 1 (3 hrs). Price: £4000.00. Scope: test. Damage: test. Please take the car and start working on it.', 0, '2026-10-04 00:20:14'),
('970cac68-7f75-4f53-85b5-79de275c90db', 'ws_pbs_autos_001', 'usr_tech_habibi', 'job_2b6bb23f', 'BAY_ASSIGNED', '🚗 New Job in bay 1: test test (TEST) (3 hrs)', 'Admin completed Scope & Pricing for test test (TEST). Allocated to bay 1 (3 hrs). Price: £4000.00. Scope: test. Damage: test. Please take the car and start working on it.', 0, '2026-10-04 00:20:51'),
('ffaff87f-0ba6-414f-872d-1ba3efe9e781', 'ws_pbs_autos_001', 'usr_tech_habibi', 'job_2b6bb23f', 'BAY_ASSIGNED', 'Car Allocated to Panel Prep – Bay 1', 'test test (TEST) has been allocated to Panel Prep – Bay 1.', 0, '2026-10-04 00:21:11'),
('8871de72-788a-4da9-a63b-fe311cfc4af2', 'ws_pbs_autos_001', 'usr_tech_habibi', 'job_2b6bb23f', 'STAGE_MOVED', 'Bay Stage Updated: bay 1', 'test test (TEST) was moved to bay 1 by PBS Autos Admin.', 0, '2026-10-04 00:21:11'),
('adbe17d7-76fc-490b-81a3-037b529d2eac', 'ws_pbs_autos_001', 'usr_admin_001', 'job_2b6bb23f', 'GENERAL', 'Vehicle Ready for Handover: test test (TEST)', 'Spray & paint completed by PBS Autos Admin! test test (TEST) is Ready for Handover. Please collect payment (£4000.00) and complete customer handover.', 0, '2026-10-04 00:21:47'),
('45d6e6ff-c6ad-4605-991a-443654ef1044', 'ws_pbs_autos_001', 'usr_bookin_001', 'job_2b6bb23f', 'GENERAL', 'Vehicle Ready for Handover: test test (TEST)', 'Spray & paint completed by PBS Autos Admin! test test (TEST) is Ready for Handover. Please collect payment (£4000.00) and complete customer handover.', 0, '2026-10-04 00:21:47'),
('7731c59e-4ea4-4a62-9002-bbbfe6769821', 'ws_pbs_autos_001', 'usr_tech_ismail', 'job_2b6bb23f', 'GENERAL', 'Vehicle Ready for Handover: test test (TEST)', 'Spray & paint completed by PBS Autos Admin! test test (TEST) is Ready for Handover. Please collect payment (£4000.00) and complete customer handover.', 0, '2026-10-04 00:21:47'),
('266c6905-0011-41ef-b6c4-5f1e7b54844d', 'ws_pbs_autos_001', 'usr_admin_001', 'job_42449e54', 'GENERAL', 'Vehicle Ready for Handover: Mercedes-Benz C220d (GC24 NEW)', 'Spray & paint completed by PBS Autos Admin! Mercedes-Benz C220d (GC24 NEW) is Ready for Handover. Please collect payment (£0.00) and complete customer handover.', 0, '2026-10-04 00:30:18'),
('d6d40be0-e98b-497d-893c-fed87919a6eb', 'ws_pbs_autos_001', 'usr_bookin_001', 'job_42449e54', 'GENERAL', 'Vehicle Ready for Handover: Mercedes-Benz C220d (GC24 NEW)', 'Spray & paint completed by PBS Autos Admin! Mercedes-Benz C220d (GC24 NEW) is Ready for Handover. Please collect payment (£0.00) and complete customer handover.', 0, '2026-10-04 00:30:18'),
('9103f6eb-557f-4c67-bcdc-fff83f305576', 'ws_pbs_autos_001', 'usr_tech_ismail', 'job_42449e54', 'GENERAL', 'Vehicle Ready for Handover: Mercedes-Benz C220d (GC24 NEW)', 'Spray & paint completed by PBS Autos Admin! Mercedes-Benz C220d (GC24 NEW) is Ready for Handover. Please collect payment (£0.00) and complete customer handover.', 0, '2026-10-04 00:30:18'),
('7412e608-e4b5-4c91-9d1a-b52080bcd6c3', 'ws_pbs_autos_001', 'usr_tech_habibi', 'job_e8906424', 'JOB_ALLOCATED', '🚗 New Job in YARD: asd asd (ASD) (3 hrs)', 'asd asd (ASD) has been allocated to you in YARD (3 hrs). Damage: test. Please take the car and start working on it.', 0, '2026-10-04 00:36:54'),
('836de85d-25e2-44ab-a6b2-5c348ed073a9', 'ws_pbs_autos_001', 'usr_tech_habibi', 'job_e8906424', 'BAY_ASSIGNED', '🚗 New Job in bay 1: asd asd (ASD) (3 hrs)', 'Admin completed Scope & Pricing for asd asd (ASD). Allocated to bay 1 (3 hrs). Scope: test. Damage: test. Please take the car and start working on it.', 0, '2026-10-04 00:37:06'),
('379864f1-e545-4e3a-9470-e8298033b637', 'ws_pbs_autos_001', 'usr_tech_habibi', 'job_e8906424', 'BAY_ASSIGNED', '🚗 New Job in bay 1: asd asd (ASD) (4 hrs)', 'Admin completed Scope & Pricing for asd asd (ASD). Allocated to bay 1 (4 hrs). Scope: test. Damage: test. Please take the car and start working on it.', 0, '2026-10-04 00:41:16'),
('a194ca64-438f-45c1-b962-96930edfffc6', 'ws_pbs_autos_001', 'usr_tech_habibi', 'job_e8906424', 'BAY_ASSIGNED', '🚗 New Job in bay 1: asd asd (ASD) (4 hrs)', 'Admin completed Scope & Pricing for asd asd (ASD). Allocated to bay 1 (4 hrs). Scope: test. Damage: test. Please take the car and start working on it.', 0, '2026-10-04 00:41:35'),
('e7c751c0-582e-4a74-929c-877ec14d1461', 'ws_pbs_autos_001', 'usr_tech_paajii', 'job_e8906424', 'BAY_ASSIGNED', '🚗 New Job in bay 2: asd asd (ASD) (4 hrs)', 'Admin completed Scope & Pricing for asd asd (ASD). Allocated to bay 2 (4 hrs). Scope: test. Damage: test. Please take the car and start working on it.', 0, '2026-10-04 00:42:21'),
('1d78a4cf-6c22-477e-926c-7cdd0f0eae38', 'ws_pbs_autos_001', 'usr_admin_001', 'job_e8906424', 'GENERAL', 'Vehicle Ready for Handover: asd asd (ASD)', 'Spray & paint completed by PBS Autos Admin! asd asd (ASD) is Ready for Handover. Please collect payment (£0.00) and complete customer handover.', 0, '2026-10-04 00:42:26'),
('2220d39d-0377-439a-a02f-ac69849ea925', 'ws_pbs_autos_001', 'usr_bookin_001', 'job_e8906424', 'GENERAL', 'Vehicle Ready for Handover: asd asd (ASD)', 'Spray & paint completed by PBS Autos Admin! asd asd (ASD) is Ready for Handover. Please collect payment (£0.00) and complete customer handover.', 0, '2026-10-04 00:42:26'),
('9ce113e0-7935-4868-869c-2b68030d5ab6', 'ws_pbs_autos_001', 'usr_tech_ismail', 'job_e8906424', 'GENERAL', 'Vehicle Ready for Handover: asd asd (ASD)', 'Spray & paint completed by PBS Autos Admin! asd asd (ASD) is Ready for Handover. Please collect payment (£0.00) and complete customer handover.', 0, '2026-10-04 00:42:26'),
('d07d16a6-b5f9-4a4d-b785-aed0c4a0038e', 'ws_pbs_autos_001', 'usr_tech_habibi', 'job_ea75c06f', 'BAY_ASSIGNED', '🚗 New Job in bay 1: test2 test2 (TEST2) (4 hrs)', 'Admin completed Scope & Pricing for test2 test2 (TEST2). Allocated to bay 1 (4 hrs). Price: £3000.00. Scope: test2. Damage: test2. Please take the car and start working on it.', 0, '2026-10-04 01:02:22'),
('5e3dc40d-cd7c-4544-8f9d-a0bec378f875', 'ws_pbs_autos_001', 'usr_tech_habibi', 'job_397066f0', 'JOB_ALLOCATED', '🚗 New Job in PANEL PREP BAY 1: test3 test3 (TEST3) (3 hrs)', 'test3 test3 (TEST3) has been allocated to you in PANEL PREP BAY 1 (3 hrs). Damage: test3. Please take the car and start working on it.', 0, '2026-10-04 01:05:01'),
('f1a00501-8fac-4c9f-a881-e09ef1e33924', 'ws_pbs_autos_001', 'usr_tech_habibi', 'job_ea75c06f', 'BAY_ASSIGNED', 'Car Allocated to PANEL PREP BAY 2', 'test2 test2 (TEST2) has been allocated to PANEL PREP BAY 2.', 0, '2026-10-04 01:06:22'),
('3dac55dc-26f7-4316-ac08-12c6dfadbb39', 'ws_pbs_autos_001', 'usr_tech_habibi', 'job_ea75c06f', 'STAGE_MOVED', 'Bay Stage Updated: PANEL PREP BAY 2', 'test2 test2 (TEST2) was moved to PANEL PREP BAY 2 by PBS Autos Admin.', 0, '2026-10-04 01:06:22'),
('ad927dcb-0a2a-40b2-b17b-d10d733de29e', 'ws_pbs_autos_001', 'usr_tech_habibi', 'job_ea75c06f', 'BAY_ASSIGNED', 'Car Allocated to PANEL PREP BAY 1', 'test2 test2 (TEST2) has been allocated to PANEL PREP BAY 1.', 0, '2026-10-04 01:06:28'),
('0f9541d6-215b-459b-9af0-a49bd89b8cff', 'ws_pbs_autos_001', 'usr_tech_habibi', 'job_ea75c06f', 'STAGE_MOVED', 'Bay Stage Updated: PANEL PREP BAY 1', 'test2 test2 (TEST2) was moved to PANEL PREP BAY 1 by PBS Autos Admin.', 0, '2026-10-04 01:06:28'),
('d5de2c80-28ee-47b7-b437-ebab24fbcdbf', 'ws_pbs_autos_001', 'usr_admin_001', 'job_ea75c06f', 'GENERAL', 'Vehicle Ready for Handover: test2 test2 (TEST2)', 'Spray & paint completed by PBS Autos Admin! test2 test2 (TEST2) is Ready for Handover. Please collect payment (£3000.00) and complete customer handover.', 0, '2026-10-04 01:07:32'),
('62658f75-44bc-47f6-8a1c-11af2adf90ca', 'ws_pbs_autos_001', 'usr_bookin_001', 'job_ea75c06f', 'GENERAL', 'Vehicle Ready for Handover: test2 test2 (TEST2)', 'Spray & paint completed by PBS Autos Admin! test2 test2 (TEST2) is Ready for Handover. Please collect payment (£3000.00) and complete customer handover.', 0, '2026-10-04 01:07:32'),
('eafe49ef-70c3-4e57-b6ed-eb73239d7552', 'ws_pbs_autos_001', 'usr_tech_ismail', 'job_ea75c06f', 'GENERAL', 'Vehicle Ready for Handover: test2 test2 (TEST2)', 'Spray & paint completed by PBS Autos Admin! test2 test2 (TEST2) is Ready for Handover. Please collect payment (£3000.00) and complete customer handover.', 0, '2026-10-04 01:07:32'),
('7c3f2361-4584-4b09-ae3e-f6ac55500a87', 'ws_pbs_autos_001', 'usr_tech_habibi', 'job_1cf0a3fa', 'BAY_ASSIGNED', '🚗 New Job in PANEL PREP BAY 1: test4 test4 (TEST4) (3 hrs)', 'Admin completed Scope & Pricing for test4 test4 (TEST4). Allocated to PANEL PREP BAY 1 (3 hrs). Price: £3000.00. Scope: test4. Damage: test4. Please take the car and start working on it.', 0, '2026-10-04 01:15:46'),
('c999690c-0d65-4690-92eb-b4dc6635fe9d', 'ws_pbs_autos_001', 'usr_tech_chris', 'job_1cf0a3fa', 'READY_FOR_SPRAY', 'Vehicle Free from Bay 1 — Waiting for Spray', 'test4 test4 (TEST4) is free from Bay 1 and assigned to you in Sprayer 1 (Paint Booth)! Please prepare spray booth and apply finish.', 0, '2026-10-04 01:16:14'),
('c50fe4d3-4ccb-48f7-979d-0786f4e9e808', 'ws_pbs_autos_001', 'usr_tech_chris', 'job_397066f0', 'READY_FOR_SPRAY', 'Vehicle Free from Bay 1 — Waiting for Spray', 'test3 test3 (TEST3) is free from Bay 1 and assigned to you in Sprayer 1 (Paint Booth)! Please prepare spray booth and apply finish.', 0, '2026-10-04 01:16:20');

-- --------------------------------------------------------
-- Table structure for table `push_subscriptions`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `push_subscriptions`;
CREATE TABLE `push_subscriptions` (
  `id` VARCHAR(64) NOT NULL,
  `user_id` VARCHAR(64) NOT NULL,
  `workshop_id` VARCHAR(64) NOT NULL,
  `endpoint` VARCHAR(500) NOT NULL,
  `p256dh` VARCHAR(255) NOT NULL,
  `auth` VARCHAR(255) NOT NULL,
  `user_agent` VARCHAR(255) NULL,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_push_subscriptions_endpoint` (`endpoint`),
  CONSTRAINT `fk_push_subscriptions_workshop_id_0` FOREIGN KEY (`workshop_id`) REFERENCES `workshops` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_push_subscriptions_user_id_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `push_subscriptions`
INSERT INTO `push_subscriptions` (`id`, `user_id`, `workshop_id`, `endpoint`, `p256dh`, `auth`, `user_agent`, `created_at`, `updated_at`) VALUES
('sub_8ddfadec', 'usr_admin_001', 'ws_pbs_autos_001', 'https://fcm.googleapis.com/fcm/send/ffQfG20xkEA:APA91bFGRfukKv_iNLKxiZn6YiKydEFYmtTJVHRwtyRTyQVjaEuy2YRC4-Czcdr1KOiXdRYqqFNnoXk39JyTTxOBARjoW6-ktfto8mNVGNoze2f27KVr3mvX8v-5ApZamxonFtZN7S1J', 'BCx4kBZbhjrbFwxxVCqk7PMMhO_osGtZk5aQ3UMyuzmFo5t2r8TEvl2Nx6nILElm4dMneTT0XGnkfTZSi7m1SOY', '3Iw7IkJd-JgGTlqrafUbSg', 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/153.0.0.0 Mobile Safari/537.36', '2026-09-18 15:58:57', '2026-09-18 15:58:57');

-- --------------------------------------------------------
-- Table structure for table `traders`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `traders`;
CREATE TABLE `traders` (
  `id` VARCHAR(64) NOT NULL,
  `workshop_id` VARCHAR(64) NOT NULL,
  `company_name` VARCHAR(255) NOT NULL,
  `contact_person` VARCHAR(255) NULL,
  `phone` VARCHAR(191) NOT NULL,
  `email` VARCHAR(191) NULL,
  `address` LONGTEXT NULL,
  `postcode` VARCHAR(191) NULL,
  `vat_number` VARCHAR(255) NULL,
  `account_ref` VARCHAR(255) NULL,
  `discount_rate` DECIMAL(12, 2) NULL DEFAULT 0.0,
  `notes` LONGTEXT NULL,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_traders_workshop_id_0` FOREIGN KEY (`workshop_id`) REFERENCES `workshops` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `traders`
INSERT INTO `traders` (`id`, `workshop_id`, `company_name`, `contact_person`, `phone`, `email`, `address`, `postcode`, `vat_number`, `account_ref`, `discount_rate`, `notes`, `created_at`) VALUES
('trd_c308446f', 'ws_pbs_autos_001', 'H2 AUTOS', 'HASSAN', '07587055192', '', '', '', '', '', 0, '', '2026-09-18 15:29:59'),
('trd_9b1eeab9', 'ws_pbs_autos_001', 'IK UNIQUE CARS', 'IMRAN', '07784680043', '', 'Unit 7b, Chatsworth Place', 'ST3 1LZ', '', '', 0, '', '2026-09-19 12:26:21'),
('trd_97ab49e9', 'ws_pbs_autos_001', 'PRO CAR HIRE', 'NAD', '07791249932', '', '', '', '', '', 0, '', '2026-09-19 12:31:18'),
('trd_7995161f', 'ws_pbs_autos_001', 'EJ CARS', 'JAFFAR', '07914386135', '', '', '', '', '', 0, '', '2026-10-02 10:19:48');

-- --------------------------------------------------------
-- Table structure for table `workshop_templates`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `workshop_templates`;
CREATE TABLE `workshop_templates` (
  `id` VARCHAR(64) NOT NULL,
  `workshop_id` VARCHAR(64) NOT NULL,
  `template_key` VARCHAR(191) NOT NULL,
  `name` VARCHAR(255) NOT NULL,
  `category` VARCHAR(191) NOT NULL,
  `subject` VARCHAR(255) NULL,
  `content` LONGTEXT NOT NULL,
  `settings_json` LONGTEXT NULL DEFAULT '{}',
  `updated_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_workshop_template` (`workshop_id`, `template_key`),
  CONSTRAINT `fk_workshop_templates_workshop_id_0` FOREIGN KEY (`workshop_id`) REFERENCES `workshops` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `workshop_templates`
INSERT INTO `workshop_templates` (`id`, `workshop_id`, `template_key`, `name`, `category`, `subject`, `content`, `settings_json`, `updated_at`) VALUES
('tpl_25ccf14d', 'ws_pbs_autos_001', 'intake_damage_sheet', 'Vehicle Intake & Damage Inspection Sheet', 'PRINT', 'PBS Autos Bodyshop Vehicle Intake & Damage Inspection Report', '158-168 Uttoxeter Rd, Longton, Stoke-on-Trent ST3 1QH, United Kingdom • Tel: +44 7376 926728 • service@pbsautos.co.uk\n\nBody Panel Repairs & Accident Damage Specialists\n\nAll pre-existing panel scratches, dents and rust verified prior to work commencement.', '{"companyHeader":"PBS Autos","subHeader":"Body Panel Repairs & Accident Damage Specialists","contactLine":"158-168 Uttoxeter Rd, Longton, Stoke-on-Trent ST3 1QH, United Kingdom • Tel: +44 7376 926728 • service@pbsautos.co.uk","disclaimer":"PBS Autos confirms all vehicle bodywork condition logged accurately at time of check-in. Any additional accident damage identified following panel stripping will be recorded immediately.","showDiagram":true,"showSignatures":true}', '2026-09-18 14:39:48'),
('tpl_dddc9702', 'ws_pbs_autos_001', 'bodyshop_invoice', 'Bodyshop Invoice & Official Receipt', 'PRINT', 'PBS Autos Official Repair Invoice', 'Thank you for choosing PBS Autos. All bodywork, panel alignment, and paint refinishing is backed by our full workshop guarantee.', '{"paymentTerms":"Payment due upon collection of vehicle. Bank transfer or chip & PIN accepted.","guaranteeNote":"All paintwork and panel repairs are guaranteed for 3 years against defects.","bankDetails":"Sort Code: 20-00-00 | Account: 12345678 | Ref: Invoice Number"}', '2026-09-18 14:39:48'),
('tpl_ff2f7bb0', 'ws_pbs_autos_001', 'email_damage_report', 'Client Damage Inspection Report (Email)', 'EMAIL', 'PBS Autos Bodyshop Intake & Damage Inspection Report — {REGISTRATION}', 'Dear {CUSTOMER_NAME},\n\nPlease find attached the official Bodyshop Intake & Damage Inspection Report for your vehicle {REGISTRATION} ({MAKE} {MODEL}) booked in on {BOOKING_DATE}.\n\nOur certified technicians have logged the pre-existing panel condition and initiated the agreed bodywork schedule.', '{"includeFullPanelGrid":true,"includePhotos":true}', '2026-09-18 14:39:48'),
('tpl_170bac1f', 'ws_pbs_autos_001', 'email_paid_receipt', 'Official Paid Receipt (Email)', 'EMAIL', 'Official Paid Receipt: Invoice #{INVOICE_NUMBER} — {REGISTRATION} (PBS Autos)', 'Dear {CUSTOMER_NAME},\n\nThank you for settling Invoice #{INVOICE_NUMBER} for £{TOTAL_AMOUNT}. Your payment has been received in full.\n\nAll bodywork, panel alignment, and paint refinishing is backed by our full PBS Autos guarantee.', '{"showVatBreakdown":false,"thankYouMessage":"Thank you for your valued custom."}', '2026-09-18 14:39:48'),
('tpl_fdeafca0', 'ws_pbs_autos_001', 'email_ready_collection', 'Vehicle Ready for Collection (Email/SMS)', 'EMAIL', 'Vehicle Ready for Collection: {REGISTRATION} ({MAKE} {MODEL}) — PBS Autos', 'Dear {CUSTOMER_NAME},\n\nGreat news! Your vehicle {REGISTRATION} ({MAKE} {MODEL}) has completed all panel preparation, paint booth refinishing, and quality inspections.\n\nYour vehicle is now fully prepared and ready for collection at our workshop.\n\nWorkshop Address: 158-168 Uttoxeter Rd, Longton, Stoke-on-Trent ST3 1QH, United Kingdom\nCollection Hours: Mon-Fri 08:30 - 17:30', '{"collectionAddress":"158-168 Uttoxeter Rd, Longton, Stoke-on-Trent ST3 1QH, United Kingdom","phoneContact":"+44 7376 926728"}', '2026-09-18 14:39:48');

-- --------------------------------------------------------
-- Table structure for table `workshop_bays`
-- --------------------------------------------------------
DROP TABLE IF EXISTS `workshop_bays`;
CREATE TABLE `workshop_bays` (
  `id` VARCHAR(64) NOT NULL,
  `workshop_id` VARCHAR(64) NOT NULL,
  `name` VARCHAR(255) NOT NULL,
  `type` VARCHAR(191) NOT NULL,
  `technician_id` VARCHAR(64) NULL,
  `is_active` INT NOT NULL DEFAULT 1,
  `sort_order` INT NOT NULL DEFAULT 0,
  `created_at` VARCHAR(255) NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  CONSTRAINT `fk_workshop_bays_technician_id_0` FOREIGN KEY (`technician_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_workshop_bays_workshop_id_1` FOREIGN KEY (`workshop_id`) REFERENCES `workshops` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Dumping data for table `workshop_bays`
INSERT INTO `workshop_bays` (`id`, `workshop_id`, `name`, `type`, `technician_id`, `is_active`, `sort_order`, `created_at`) VALUES
('bay_1', 'ws_pbs_autos_001', 'Panel Prep – Bay 1', 'BAY', 'usr_tech_habibi', 1, 1, '2026-09-18 14:34:00'),
('bay_2', 'ws_pbs_autos_001', 'Panel Prep – Bay 2', 'BAY', 'usr_tech_paajii', 1, 2, '2026-09-18 14:34:00'),
('sprayer_1', 'ws_pbs_autos_001', 'Sprayer 1 (Paint Booth)', 'SPRAYER', 'usr_tech_chris', 1, 1, '2026-09-18 14:34:00');

COMMIT;
SET FOREIGN_KEY_CHECKS = 1;
