-- INSERT Vehicle Purchase Agreement Form Template
-- This script adds the Vehicle Purchase Agreement form to the form_templates table
-- You will need to:
-- 1. Find the ID of "Legal & Contracts" category or use the correct category ID
-- 2. Replace [CATEGORY_ID] with the actual category ID
-- 3. Run this script in phpMyAdmin

INSERT INTO `form_templates` (
    `category_id`,
    `form_name`,
    `description`,
    `form_fields`,
    `created_by`,
    `created_at`
) VALUES (
    [CATEGORY_ID],
    'Vehicle Purchase Agreement',
    'UK garage/dealer stock purchase form - suitable for private seller, trader, auction, customer part-exchange or business purchase',
    '[
        {
            "label": "Agreement reference / stock number",
            "type": "text",
            "required": false
        },
        {
            "label": "Date of purchase",
            "type": "date",
            "required": true
        },
        {
            "label": "Time of purchase",
            "type": "text",
            "required": false
        },
        {
            "label": "Place of purchase",
            "type": "text",
            "required": true
        },
        {
            "label": "Purchase agreed by",
            "type": "text",
            "required": true
        },
        {
            "label": "Seller full legal name",
            "type": "text",
            "required": true
        },
        {
            "label": "Trading / business name, if applicable",
            "type": "text",
            "required": false
        },
        {
            "label": "Seller address",
            "type": "text",
            "required": true
        },
        {
            "label": "Seller postcode",
            "type": "text",
            "required": true
        },
        {
            "label": "Seller telephone",
            "type": "tel",
            "required": true
        },
        {
            "label": "Seller email",
            "type": "email",
            "required": true
        },
        {
            "label": "Company number / VAT number, if applicable",
            "type": "text",
            "required": false
        },
        {
            "label": "Garage legal name",
            "type": "text",
            "required": true
        },
        {
            "label": "Garage trading name",
            "type": "text",
            "required": true
        },
        {
            "label": "Garage business address",
            "type": "text",
            "required": true
        },
        {
            "label": "Garage postcode",
            "type": "text",
            "required": true
        },
        {
            "label": "Garage company number",
            "type": "text",
            "required": true
        },
        {
            "label": "Garage VAT number",
            "type": "text",
            "required": true
        },
        {
            "label": "Garage telephone",
            "type": "tel",
            "required": true
        },
        {
            "label": "Garage email",
            "type": "email",
            "required": true
        },
        {
            "label": "Authorised buyer name",
            "type": "text",
            "required": true
        },
        {
            "label": "Position / role",
            "type": "text",
            "required": false
        },
        {
            "label": "Vehicle registration number",
            "type": "text",
            "required": true
        },
        {
            "label": "VIN / chassis number",
            "type": "text",
            "required": true
        },
        {
            "label": "Stock number",
            "type": "text",
            "required": false
        },
        {
            "label": "Vehicle make",
            "type": "text",
            "required": true
        },
        {
            "label": "Vehicle model",
            "type": "text",
            "required": true
        },
        {
            "label": "Trim / derivative",
            "type": "text",
            "required": false
        },
        {
            "label": "Body type",
            "type": "text",
            "required": false
        },
        {
            "label": "Colour",
            "type": "text",
            "required": false
        },
        {
            "label": "Fuel type",
            "type": "text",
            "required": false
        },
        {
            "label": "Transmission",
            "type": "text",
            "required": false
        },
        {
            "label": "Engine size",
            "type": "text",
            "required": false
        },
        {
            "label": "Date first registered",
            "type": "date",
            "required": false
        },
        {
            "label": "Current mileage",
            "type": "number",
            "required": false
        },
        {
            "label": "MOT expiry date",
            "type": "date",
            "required": false
        },
        {
            "label": "Number of keys",
            "type": "number",
            "required": false
        },
        {
            "label": "V5C document reference",
            "type": "text",
            "required": false
        },
        {
            "label": "Agreed purchase price GBP",
            "type": "number",
            "required": true
        },
        {
            "label": "Deposit paid GBP",
            "type": "number",
            "required": false
        },
        {
            "label": "Balance payable GBP",
            "type": "number",
            "required": false
        },
        {
            "label": "Payment method",
            "type": "text",
            "required": true
        },
        {
            "label": "Payment reference",
            "type": "text",
            "required": false
        },
        {
            "label": "Payment due / paid date",
            "type": "date",
            "required": false
        },
        {
            "label": "Finance settlement deduction GBP",
            "type": "number",
            "required": false
        },
        {
            "label": "Amount payable direct to seller GBP",
            "type": "number",
            "required": false
        },
        {
            "label": "Seller bank account name",
            "type": "text",
            "required": false
        },
        {
            "label": "Sort code",
            "type": "text",
            "required": false
        },
        {
            "label": "Account number",
            "type": "text",
            "required": false
        },
        {
            "label": "Payment authorised by",
            "type": "text",
            "required": false
        },
        {
            "label": "Known faults, history, finance or other disclosures",
            "type": "textarea",
            "required": false
        },
        {
            "label": "Additional notes / special conditions",
            "type": "textarea",
            "required": false
        },
        {
            "label": "Seller name (signature)",
            "type": "text",
            "required": true
        },
        {
            "label": "Seller signature date",
            "type": "date",
            "required": true
        },
        {
            "label": "Seller signature time",
            "type": "text",
            "required": false
        },
        {
            "label": "Buyer / Garage name (signature)",
            "type": "text",
            "required": true
        },
        {
            "label": "Buyer / Garage signature date",
            "type": "date",
            "required": true
        },
        {
            "label": "Buyer / Garage signature time",
            "type": "text",
            "required": false
        }
    ]',
    1,
    NOW()
);

-- ==================================================
-- INSTRUCTIONS FOR USE:
-- ==================================================
--
-- 1. FIND YOUR CATEGORY ID:
--    Go to your database and run this query to find the ID:
--    SELECT id, name FROM form_categories WHERE name LIKE '%Legal%' OR name LIKE '%Contract%';
--
-- 2. REPLACE [CATEGORY_ID]:
--    Update [CATEGORY_ID] in the INSERT statement above with the actual ID
--    For example, if the category ID is 5, change it to:
--    `category_id`, 5,
--
-- 3. REPLACE USER ID (CREATED_BY):
--    Also update the created_by value (currently 1) to your actual user ID
--    You can find this in the users table or use $_SESSION['user_id']
--
-- 4. RUN THE SCRIPT:
--    Copy the entire INSERT statement (with the corrected values)
--    Paste it into phpMyAdmin's SQL window
--    Click "Go" or "Execute"
--
-- 5. VERIFY:
--    After inserting, go to manage-forms.php
--    Select the appropriate category
--    You should see "Vehicle Purchase Agreement" in the forms list
--
-- ==================================================
