-- PDF Report Module Installation SQL

-- Create settings table for PDF report module
CREATE TABLE IF NOT EXISTS pdf_report_settings (
    id INT PRIMARY KEY AUTO_INCREMENT,
    company_logo VARCHAR(255),
    company_name VARCHAR(100) NOT NULL,
    company_address TEXT,
    company_phone VARCHAR(20),
    company_email VARCHAR(100),
    footer_text VARCHAR(255),
    created_at DATETIME NOT NULL,
    updated_at DATETIME
);

-- Insert default settings
INSERT INTO pdf_report_settings (
    company_name,
    company_address,
    company_phone,
    company_email,
    footer_text,
    created_at,
    updated_at
) VALUES (
    'Teknik Servis Sistemi',
    '',
    '',
    '',
    'Teknik Servis Otomasyon Sistemi © ' || DATE_FORMAT(NOW(), '%Y'),
    NOW(),
    NOW()
) ON DUPLICATE KEY UPDATE
    updated_at = NOW();

-- Create table for tracking generated PDFs
CREATE TABLE IF NOT EXISTS pdf_reports (
    id INT PRIMARY KEY AUTO_INCREMENT,
    filename VARCHAR(255) NOT NULL,
    file_path VARCHAR(255) NOT NULL,
    record_id INT,
    user_id INT,
    created_at DATETIME NOT NULL,
    FOREIGN KEY (record_id) REFERENCES service_records(id) ON DELETE SET NULL,
    FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
);

-- Add index for faster searches
CREATE INDEX IF NOT EXISTS idx_pdf_reports_record_id ON pdf_reports(record_id);
CREATE INDEX IF NOT EXISTS idx_pdf_reports_user_id ON pdf_reports(user_id);