import sqlite3
from datetime import datetime, timezone, timedelta

def seed_complaints():
    conn = sqlite3.connect('instance/ngo.db')
    c = conn.cursor()

    complaints_data = [
        (
            'GRV-2026-0002',
            'Sunita Verma',
            'sunita.verma@example.com',
            '+91 98112 34567',
            'Donation / 80G Query',
            'High',
            '80G Tax Exemption Certificate not received for recent online donation',
            'I made an online donation of Rs. 10,000 on November 10th for the winter relief drive via UPI (Ref: UPI-98776655). I need the 80G certificate with CIT exemption number CIT/EXEMP/DEL/80G/2026/0921 for filing my income tax returns.',
            'Resolved',
            'Dear Sunita ji, we have verified your donation in our accounts ledger and generated statutory 80G receipt #NGO/80G/2026/0103. The certified PDF copy has also been dispatched to your email address.',
            'Verified with finance team; receipt emailed to donor.',
            1,
            (datetime.now(timezone.utc) - timedelta(days=2)).strftime('%Y-%m-%d %H:%M:%S'),
            (datetime.now(timezone.utc) - timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S'),
            1,
            (datetime.now(timezone.utc) - timedelta(days=3)).strftime('%Y-%m-%d %H:%M:%S')
        ),
        (
            'GRV-2026-0003',
            'Mohit Aggarwal',
            'mohit.aggarwal@example.com',
            '+91 98765 11223',
            'Relief Aid Distribution',
            'Urgent',
            'Medicine and blanket distribution timing delay in Rohini Sector 16 camp',
            'The relief van scheduled for 10 AM at the community park arrived late by 3 hours. Many elderly residents had to wait under direct sunlight. Please ensure better coordination and backup vehicle arrangements.',
            'In Progress',
            'Thank you for bringing this to our attention. Our central logistics coordinator has been notified and vehicle maintenance procedures are being reinforced to prevent route delays.',
            'Contacted logistics supervisor Ramesh. Driver was stuck in traffic diversion.',
            1,
            (datetime.now(timezone.utc) - timedelta(hours=4)).strftime('%Y-%m-%d %H:%M:%S'),
            None,
            None,
            (datetime.now(timezone.utc) - timedelta(hours=8)).strftime('%Y-%m-%d %H:%M:%S')
        ),
        (
            'GRV-2026-0004',
            'Dr. Arvind Saxena',
            'arvind.saxena@example.com',
            '+91 99887 76655',
            'Public Suggestion',
            'Medium',
            'Suggestion to add pediatric eye-screening camp in upcoming health drive',
            'We would like to collaborate and volunteer to conduct free pediatric vision screening and distribute spectacles to underprivileged children during your December health camp.',
            'On Hold',
            'We deeply appreciate this wonderful community initiative. Our medical coordinator Dr. Mehra is currently evaluating venue capacity and will contact you by Friday.',
            'Awaiting approval from health camp steering committee on equipment space.',
            1,
            (datetime.now(timezone.utc) - timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S'),
            None,
            None,
            (datetime.now(timezone.utc) - timedelta(days=1, hours=5)).strftime('%Y-%m-%d %H:%M:%S')
        ),
        (
            'GRV-2026-0005',
            'Kavita Singhal',
            'kavita.singhal@example.com',
            '+91 98223 34455',
            'Volunteer / Member Issue',
            'Medium',
            'Internship completion certificate name spelling correction',
            'My internship completion certificate has my last name misspelled as Singh instead of Singhal. Kindly issue the corrected digital certificate with verification QR code.',
            'Pending',
            None,
            None,
            0,
            None,
            None,
            None,
            (datetime.now(timezone.utc) - timedelta(hours=2)).strftime('%Y-%m-%d %H:%M:%S')
        )
    ]

    for item in complaints_data:
        t_num = item[0]
        c.execute('SELECT id FROM feedbacks WHERE ticket_number = ?', (t_num,))
        if not c.fetchone():
            c.execute('''
                INSERT INTO feedbacks (
                    ticket_number, name, email, phone, category, priority,
                    subject, message, status, admin_reply, internal_notes,
                    email_sent, email_sent_at, resolved_at, resolved_by_id, submitted_at
                ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
            ''', item)
            print(f'Inserted complaint {t_num}')

    conn.commit()
    c.execute('SELECT ticket_number, name, category, status FROM feedbacks')
    for row in c.fetchall():
        print('Complaint:', row)
    conn.close()

if __name__ == '__main__':
    seed_complaints()
