-- Service orders
CREATE TABLE IF NOT EXISTS service_orders (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  vehicle_id BIGINT UNSIGNED NOT NULL,
  cliente_id BIGINT UNSIGNED NULL,
  status ENUM('aberta','em_andamento','aguardando','concluida','faturada','cancelada') NOT NULL DEFAULT 'aberta',
  descricao TEXT NULL,
  tecnico_responsavel VARCHAR(160) NULL,
  valor_total_cents BIGINT NULL DEFAULT 0,
  aberta_em DATETIME NULL,
  fechada_em DATETIME NULL,
  created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
  INDEX idx_so_vehicle (vehicle_id),
  INDEX idx_so_cliente (cliente_id),
  INDEX idx_so_status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;