-- ============================================================
--  mercyv-garage  |  install.sql
--  Einmalig ausführen!
-- ============================================================

CREATE TABLE IF NOT EXISTS `mercyv_garages` (
  `id`               VARCHAR(80)  NOT NULL,
  `label`            VARCHAR(100) NOT NULL DEFAULT 'Garage',
  `type`             VARCHAR(20)  NOT NULL DEFAULT 'normal',
  `access`           VARCHAR(50)  NOT NULL DEFAULT 'none',
  `gang`             VARCHAR(50)  NOT NULL DEFAULT 'none',
  `blip_show`        TINYINT(1)   NOT NULL DEFAULT 1,
  `blip_type`        INT          NOT NULL DEFAULT 357,
  `blip_colour`      INT          NOT NULL DEFAULT 3,
  `npc_model`        VARCHAR(100) NOT NULL DEFAULT 'a_m_m_prolhost_01',
  `npc_x`            FLOAT        NOT NULL DEFAULT 0,
  `npc_y`            FLOAT        NOT NULL DEFAULT 0,
  `npc_z`            FLOAT        NOT NULL DEFAULT 0,
  `npc_heading`      FLOAT        NOT NULL DEFAULT 0,
  `spawn_x`          FLOAT        NOT NULL DEFAULT 0,
  `spawn_y`          FLOAT        NOT NULL DEFAULT 0,
  `spawn_z`          FLOAT        NOT NULL DEFAULT 0,
  `spawn_heading`    FLOAT        NOT NULL DEFAULT 0,
  `park_x`           FLOAT        NOT NULL DEFAULT 0,
  `park_y`           FLOAT        NOT NULL DEFAULT 0,
  `park_z`           FLOAT        NOT NULL DEFAULT 0,
  `showcar_x`        FLOAT                 DEFAULT NULL,
  `showcar_y`        FLOAT                 DEFAULT NULL,
  `showcar_z`        FLOAT                 DEFAULT NULL,
  `showcar_heading`  FLOAT                 DEFAULT 0,
  `cam_x`            FLOAT                 DEFAULT NULL,
  `cam_y`            FLOAT                 DEFAULT NULL,
  `cam_z`            FLOAT                 DEFAULT NULL,
  `cam_rot_z`        FLOAT                 DEFAULT -20,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Klassen-Spalte zu owned_vehicles (ESX) hinzufügen
ALTER TABLE `owned_vehicles`
  ADD COLUMN IF NOT EXISTS `veh_class` TINYINT DEFAULT 0;

-- ============================================================
--  Standard-Garagen aus der Config (können ingame geändert werden)
-- ============================================================

INSERT IGNORE INTO `mercyv_garages`
  (id, label, type, access, blip_show, blip_type, blip_colour, npc_model,
   npc_x, npc_y, npc_z, npc_heading,
   spawn_x, spawn_y, spawn_z, spawn_heading,
   park_x, park_y, park_z,
   showcar_x, showcar_y, showcar_z, showcar_heading,
   cam_x, cam_y, cam_z, cam_rot_z)
VALUES
('Garage A','Garage A','normal','none',1,357,3,'a_m_m_prolhost_01',
 214.5806,-806.8969,30.8052,336.3445,
 233.7616,-802.9507,30.4636,71.0069,
 214.9846,-790.6285,30.8301,
 236.39,-779.89,30.67,161.68,
 234.57,-785.1,30.59,-20.0),

('Garage B','Garage B','normal','none',1,357,3,'a_m_m_prolhost_01',
 275.95,-344.06,45.17,165.24,
 292.79,-332.22,44.92,161.25,
 271.68,-341.61,44.92,
 274.63,-330.28,44.70,164.27,
 273.08,-335.04,44.92,-20.0),

('Garage D','Garage D','normal','none',1,357,3,'a_m_m_prolhost_01',
 68.35,13.85,69.21,167.77,
 73.24,11.78,68.85,155.92,
 73.24,11.78,68.85,
 59.35,24.31,69.73,245.08,
 64.78,22.19,69.54,70.0),

('Garage E','Garage E','normal','none',1,357,3,'a_m_m_prolhost_01',
 363.48,296.86,103.50,244.81,
 367.98,296.57,103.42,345.36,
 367.98,296.57,103.42,
 376.33,288.82,103.20,69.26,
 371.18,290.66,103.31,-110.0),

('Garage F','Garage F','normal','none',1,357,3,'a_m_m_prolhost_01',
 -1158.51,-740.67,19.89,41.16,
 -1169.03,-743.49,19.63,42.38,
 -1169.03,-743.49,19.63,
 -1145.2,-759.03,18.82,39.92,
 -1148.57,-754.86,18.97,-140.0),

('Garage G','Garage G','normal','none',1,357,3,'a_m_m_prolhost_01',
 -795.33,-2023.8,9.17,66.37,
 -790.11,-2022.68,8.87,58.85,
 -791.39,-2030.26,8.87,
 -763.11,-2042.28,8.91,37.29,
 -766.54,-2037.82,8.9,-143.0),

('Garage H','Garage H','normal','none',1,357,3,'a_m_m_prolhost_01',
 -468.87,-819.67,30.52,358.04,
 -472.16,-812.83,30.53,179.63,
 -453.49,-814.23,30.58,
 -472.02,-800.43,30.54,183.47,
 -472.16,-806.15,30.54,-3.0),

('Garage I','Garage I','normal','none',1,357,3,'a_m_m_prolhost_01',
 1142.38,2661.28,38.16,92.19,
 1137.57,2674.86,38.25,1.08,
 1137.59,2653.02,38.0,
 1121.15,2665.03,38.02,266.97,
 1127.68,2664.84,38.02,88.0),

('Garage J','Garage J','normal','none',1,357,3,'a_m_m_prolhost_01',
 83.51,6420.3,31.76,313.17,
 85.93,6426.8,31.34,38.93,
 79.68,6417.33,31.28,
 112.65,6396.47,31.31,42.5,
 107.37,6402.14,31.33,-138.0),

('Garage K','Boot Garage','boat','none',1,356,3,'a_m_m_prolhost_01',
 -717.9,-1327.46,1.6,50.86,
 -718.05,-1334.24,-0.44,222.71,
 -718.03,-1334.21,1.0,
 -723.7,-1329.22,-0.11,229.03,
 -719.57,-1332.72,1.41,50.0),

('Garage L','Flugzeug Garage','aircraft','none',1,359,3,'a_m_m_prolhost_01',
 -1251.69,-3399.94,13.94,59.19,
 -1246.91,-3355.14,13.95,330.68,
 -1246.91,-3355.14,13.95,
 -1273.01,-3402.28,13.94,331.01,
 -1268.42,-3394.32,13.94,-210.0),

('Garage M','Garage M','normal','none',1,357,3,'a_m_m_prolhost_01',
 271.94,-1509.32,29.18,87.30,
 243.22,-1502.84,29.14,222.92,
 243.22,-1502.84,29.14,
 253.68,-1511.65,29.14,260.14,
 256.95,-1500.42,29.14,-200.0),

('Garage N','Garage N','normal','none',1,357,3,'a_m_m_prolhost_01',
 -1134.78,2682.73,18.46,132.28,
 -1155.64,2665.05,18.09,223.0,
 -1141.49,2680.13,18.09,
 -1157.10,2672.85,18.09,175.18,
 -1145.82,2670.54,19.75,-280.0),

('Garage T','Garage T','normal','none',1,357,3,'a_m_m_prolhost_01',
 302.3,-189.94,61.57,73.01,
 288.09,-194.55,61.57,249.13,
 301.1,-183.12,61.59,
 274.64,-189.47,61.57,252.0,
 279.92,-191.36,61.57,61.57),

('Impound Garage','Abschlepphof','impound','none',1,68,3,'a_m_m_prolhost_01',
 406.88,-1625.23,29.29,229.89,
 408.0,-1645.66,29.29,228.92,
 408.0,-1645.66,29.29,
 401.4,-1639.93,29.29,230.79,
 406.0,-1643.48,29.29,50.29),

('Impound Boat','Abschlepphof Boot','impoundboat','none',1,357,3,'a_m_m_prolhost_01',
 -769.64,-1425.65,1.60,230.0,
 -786.56,-1424.55,-0.51,133.50,
 -786.56,-1424.55,-0.51,
 -786.56,-1424.55,-0.51,133.50,
 -795.95,-1436.94,3.06,322.48),

('Impound Plane','Abschlepphof Flugzeug','impoundplane','none',1,357,3,'a_m_m_prolhost_01',
 -1030.27,-3016.30,13.95,339.01,
 -979.81,-2995.32,13.95,69.51,
 -979.81,-2995.32,13.95,
 -984.89,-3012.54,13.95,61.43,
 -994.19,-3008.20,13.95,236.98),

('police','Polizei Garage','jobgarage','police',0,357,3,'ig_solomon',
 457.60,-977.66,21.95,87.43,
 449.80,-971.60,21.45,177.42,
 449.42,-979.14,21.45,
 417.47,-974.65,21.45,177.18,
 428.37,-974.73,21.45,-270.0),

('ambulance','Ambulanz Garage','jobgarage','ambulance',0,357,3,'ig_solomon',
 -286.81,-588.56,27.78,1.87,
 -286.29,-576.06,27.63,85.73,
 -285.72,-580.70,27.63,
 -305.70,-567.67,27.63,296.93,
 -311.61,-563.86,27.63,-110.0);

-- ============================================================
--  Vehicle Persist: last_coords Spalte
--  (wird automatisch vom Script genutzt)
-- ============================================================

-- ESX:
ALTER TABLE `owned_vehicles`
  ADD COLUMN IF NOT EXISTS `veh_class`   TINYINT      DEFAULT 0,
  ADD COLUMN IF NOT EXISTS `last_coords` VARCHAR(255) DEFAULT NULL;

-- QBCore:
-- ALTER TABLE `player_vehicles`
--   ADD COLUMN IF NOT EXISTS `veh_class`   TINYINT      DEFAULT 0,
--   ADD COLUMN IF NOT EXISTS `last_coords` VARCHAR(255) DEFAULT NULL;
