-- Lost & Found Database Seed Data
-- MySQL/MariaDB Database

SET NAMES utf8mb4;
SET CHARACTER SET utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ============================================
-- CLEAR EXISTING DATA (Optional - untuk re-seed)
-- ============================================
-- TRUNCATE TABLE notifications;
-- TRUNCATE TABLE revision_logs;
-- TRUNCATE TABLE match_results;
-- TRUNCATE TABLE claim_verifications;
-- TRUNCATE TABLE audit_logs;
-- TRUNCATE TABLE archives;
-- TRUNCATE TABLE claims;
-- TRUNCATE TABLE items;
-- TRUNCATE TABLE lost_items;
-- TRUNCATE TABLE categories;
-- TRUNCATE TABLE users;
-- TRUNCATE TABLE roles;

-- ============================================
-- SEED ROLES
-- ============================================
INSERT INTO roles (name, description) VALUES
('admin', 'Administrator with full access'),
('manager', 'Manager/Cleaning Service - can verify claims'),
('user', 'Regular user/student');

-- ============================================
-- SEED CATEGORIES
-- ============================================
INSERT INTO categories (name, slug, description) VALUES
('Pakaian', 'pakaian', 'Jaket, baju, celana, dll'),
('Alat Makan', 'alat_makan', 'Botol minum, lunchbox, dll'),
('Aksesoris', 'aksesoris', 'Jam tangan, gelang, kacamata, dll'),
('Elektronik', 'elektronik', 'Kalkulator, mouse, headset, charger, dll'),
('Alat Tulis', 'alat_tulis', 'Buku, pulpen, tipe-x, dll'),
('Lainnya', 'lainnya', 'Kategori lainnya');

-- ============================================
-- SEED USERS
-- Password untuk semua user: "password123"
-- Hash bcrypt: $2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi
-- ============================================

-- Admin User
INSERT INTO users (name, email, password, nrp, phone, role_id, status) VALUES
('Admin System', 'admin@lostandfound.com', '$2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', '1234567890', '081234567890', 1, 'active');

-- Manager Users
INSERT INTO users (name, email, password, nrp, phone, role_id, status) VALUES
('Pak Budi', 'manager1@lostandfound.com', '$2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', '2234567890', '081234567891', 2, 'active'),
('Bu Siti', 'manager2@lostandfound.com', '$2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', '2234567891', '081234567892', 2, 'active');

-- Regular Users (Students)
INSERT INTO users (name, email, password, nrp, phone, role_id, status) VALUES
('Ahmad Rizki', 'ahmad@student.com', '$2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', '5025211001', '081234567893', 3, 'active'),
('Siti Nurhaliza', 'siti@student.com', '$2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', '5025211002', '081234567894', 3, 'active'),
('Budi Santoso', 'budi@student.com', '$2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', '5025211003', '081234567895', 3, 'active'),
('Dewi Lestari', 'dewi@student.com', '$2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', '5025211004', '081234567896', 3, 'active'),
('Eko Prasetyo', 'eko@student.com', '$2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', '5025211005', '081234567897', 3, 'active');

-- ============================================
-- SEED ITEMS (Barang Ditemukan)
-- ============================================
INSERT INTO items (name, category_id, photo_url, location, description, date_found, status, reporter_id, reporter_name, reporter_contact, expires_at) VALUES
-- Pakaian
('Jaket Hitam Nike', 1, '', 'Gedung A lantai 2', 'Jaket hitam merk Nike ukuran M, ada logo putih di dada kiri, resleting berwarna silver', '2024-01-15 09:30:00', 'unclaimed', 2, 'Pak Budi', '081234567891', '2024-04-15 09:30:00'),
('Sweater Abu-abu', 1, '', 'Perpustakaan', 'Sweater abu-abu polos, ada tulisan "ITS" di punggung dengan huruf biru', '2024-01-18 14:20:00', 'unclaimed', 3, 'Bu Siti', '081234567892', '2024-04-18 14:20:00'),

-- Alat Makan
('Botol Minum Tupperware Biru', 2, '', 'Kantin Utama', 'Botol minum tupperware warna biru tua, ada stiker nama "RARA" di samping, tutup warna putih', '2024-01-20 12:00:00', 'unclaimed', 2, 'Pak Budi', '081234567891', '2024-04-20 12:00:00'),
('Lunchbox Pink', 2, '', 'Gedung B lantai 1', 'Kotak makan plastik warna pink dengan 2 sekat, ada gambar Hello Kitty di tutup', '2024-01-22 11:30:00', 'unclaimed', 3, 'Bu Siti', '081234567892', '2024-04-22 11:30:00'),

-- Elektronik
('Kalkulator Casio FX-991ID Plus', 4, '', 'Ruang Kelas C101', 'Kalkulator scientific Casio FX-991ID Plus, warna hitam, ada goresan kecil di layar', '2024-01-25 08:15:00', 'unclaimed', 2, 'Pak Budi', '081234567891', '2024-04-25 08:15:00'),
('Mouse Wireless Logitech', 4, '', 'Lab Komputer', 'Mouse wireless Logitech M185, warna merah, tidak ada baterai dan receiver USB', '2024-01-28 15:45:00', 'unclaimed', 3, 'Bu Siti', '081234567892', '2024-04-28 15:45:00'),
('Charger Laptop HP', 4, '', 'Perpustakaan meja 15', 'Charger laptop HP original 65W, kabel agak kusut, ujung konektor bulat', '2024-02-01 10:20:00', 'unclaimed', 2, 'Pak Budi', '081234567891', '2024-05-01 10:20:00'),

-- Aksesoris
('Jam Tangan Casio G-Shock', 3, '', 'Toilet Gedung A', 'Jam tangan Casio G-Shock warna hitam dengan strip orange, tali karet, ada goresan di layar', '2024-02-03 13:00:00', 'unclaimed', 3, 'Bu Siti', '081234567892', '2024-05-03 13:00:00'),
('Kacamata Minus', 3, '', 'Masjid Kampus', 'Kacamata minus frame hitam persegi, lensa agak tebal, ada case warna coklat', '2024-02-05 16:30:00', 'unclaimed', 2, 'Pak Budi', '081234567891', '2024-05-05 16:30:00'),

-- Alat Tulis
('Buku Kalkulus', 5, '', 'Gedung C lantai 3', 'Buku Kalkulus karangan Purcell edisi 9, sampul biru, ada coretan nama di halaman pertama (nama dicoret)', '2024-02-08 09:00:00', 'unclaimed', 3, 'Bu Siti', '081234567892', '2024-05-08 09:00:00'),
('Pensil Mekanik Rotring', 5, '', 'Studio Gambar', 'Pensil mekanik Rotring Rapid Pro 0.5mm warna silver, agak berat, ada penyok kecil di badan', '2024-02-10 14:45:00', 'unclaimed', 2, 'Pak Budi', '081234567891', '2024-05-10 14:45:00');

-- ============================================
-- SEED LOST_ITEMS (Barang Hilang)
-- ============================================
INSERT INTO lost_items (user_id, name, category_id, color, location, description, date_lost, status) VALUES
-- User Ahmad
(4, 'Jaket Hitam', 1, 'Hitam', 'Gedung A', 'Jaket hitam merk Nike ukuran M dengan logo putih di dada', '2024-01-15 08:00:00', 'active'),
(4, 'Kalkulator Casio Scientific', 4, 'Hitam', 'Ruang Kelas', 'Kalkulator scientific Casio FX-991ID Plus warna hitam', '2024-01-25 07:00:00', 'active'),

-- User Siti
(5, 'Botol Minum Biru', 2, 'Biru', 'Kantin', 'Botol tupperware biru dengan stiker nama RARA', '2024-01-20 11:00:00', 'active'),
(5, 'Jam Tangan Casio', 3, 'Hitam', 'Toilet', 'Jam tangan G-Shock hitam dengan strip orange', '2024-02-03 12:00:00', 'active'),

-- User Budi
(6, 'Mouse Wireless', 4, 'Merah', 'Lab Komputer', 'Mouse wireless Logitech warna merah tanpa receiver', '2024-01-28 14:00:00', 'active'),

-- User Dewi
(7, 'Buku Kalkulus', 5, 'Biru', 'Gedung C', 'Buku Kalkulus Purcell edisi 9 sampul biru', '2024-02-08 08:00:00', 'active'),

-- User Eko
(8, 'Kacamata Minus', 3, 'Hitam', 'Masjid', 'Kacamata frame hitam persegi dengan case coklat', '2024-02-05 15:00:00', 'active');

-- ============================================
-- SEED CLAIMS (Klaim Barang)
-- ============================================
INSERT INTO claims (item_id, user_id, description, proof_url, contact, status, notes, verified_at, verified_by) VALUES
-- Claim pending (belum diverifikasi)
(1, 4, 'Jaket Nike hitam ukuran M, ada logo putih di dada kiri, resleting silver', '', '081234567893', 'pending', NULL, NULL, NULL),
(3, 5, 'Botol tupperware biru dengan stiker nama RARA di samping, tutup putih', '', '081234567894', 'pending', NULL, NULL, NULL),

-- Claim yang sudah approved
(5, 4, 'Kalkulator Casio FX-991ID Plus warna hitam, ada goresan kecil di layar', '', '081234567893', 'approved', 'Deskripsi cocok, barang diserahkan', DATE_SUB(NOW(), INTERVAL 2 DAY), 2);

-- ============================================
-- SEED CLAIM_VERIFICATIONS
-- ============================================
INSERT INTO claim_verifications (claim_id, similarity_score, matched_keywords, verification_notes, is_auto_matched) VALUES
(1, 85.50, '["jaket", "nike", "hitam", "logo", "putih", "resleting", "silver"]', 'High similarity detected', FALSE),
(2, 92.30, '["botol", "tupperware", "biru", "stiker", "rara", "tutup", "putih"]', 'Very high similarity - likely owner', FALSE),
(3, 88.70, '["kalkulator", "casio", "hitam", "goresan", "layar"]', 'Verified and approved', FALSE);

-- ============================================
-- SEED MATCH_RESULTS (Auto-Matching)
-- ============================================
INSERT INTO match_results (lost_item_id, item_id, similarity_score, matched_fields, matched_at, is_notified) VALUES
(1, 1, 87.50, '{"name": 85, "category": 100, "description": 90}', '2024-01-15 10:00:00', TRUE),
(2, 5, 89.20, '{"name": 88, "category": 100, "description": 91}', '2024-01-25 09:00:00', TRUE),
(3, 3, 91.80, '{"name": 90, "category": 100, "color": 100, "description": 89}', '2024-01-20 13:00:00', TRUE),
(4, 8, 86.40, '{"name": 82, "category": 100, "color": 100, "description": 85}', '2024-02-03 14:00:00', TRUE),
(5, 6, 84.60, '{"name": 80, "category": 100, "color": 100, "description": 88}', '2024-01-28 16:00:00', FALSE);

-- ============================================
-- SEED NOTIFICATIONS
-- ============================================
INSERT INTO notifications (user_id, type, title, message, entity_type, entity_id, is_read, read_at) VALUES
-- Notifikasi match ditemukan
(4, 'match_found', 'Barang yang Mirip Ditemukan!', 'Kami menemukan barang yang mirip dengan laporan kehilangan Anda: Jaket Hitam Nike', 'match', 1, TRUE, DATE_SUB(NOW(), INTERVAL 1 DAY)),
(4, 'match_found', 'Barang yang Mirip Ditemukan!', 'Kami menemukan barang yang mirip dengan laporan kehilangan Anda: Kalkulator Casio FX-991ID Plus', 'match', 2, FALSE, NULL),
(5, 'match_found', 'Barang yang Mirip Ditemukan!', 'Kami menemukan barang yang mirip dengan laporan kehilangan Anda: Botol Minum Tupperware Biru', 'match', 3, FALSE, NULL),

-- Notifikasi klaim disetujui
(4, 'claim_approved', 'Klaim Disetujui!', 'Klaim Anda untuk barang Kalkulator Casio FX-991ID Plus telah disetujui. Silakan ambil barang di tempat yang ditentukan.', 'claim', 3, FALSE, NULL),

-- Notifikasi untuk manager (pending claims)
(2, 'new_claim', 'Klaim Baru', 'Ada klaim baru untuk barang: Jaket Hitam Nike dari Ahmad Rizki', 'claim', 1, FALSE, NULL),
(2, 'new_claim', 'Klaim Baru', 'Ada klaim baru untuk barang: Botol Minum Tupperware Biru dari Siti Nurhaliza', 'claim', 2, FALSE, NULL);

-- ============================================
-- SEED AUDIT_LOGS
-- ============================================
INSERT INTO audit_logs (user_id, action, entity_type, entity_id, details, ip_address, user_agent) VALUES
-- Login activities
(1, 'login', 'user', 1, 'Admin logged in', '127.0.0.1', 'Mozilla/5.0'),
(2, 'login', 'user', 2, 'Manager logged in', '127.0.0.1', 'Mozilla/5.0'),
(4, 'login', 'user', 4, 'User logged in', '127.0.0.1', 'Mozilla/5.0'),

-- Item creation activities
(2, 'create', 'item', 1, 'Item created: Jaket Hitam Nike', '127.0.0.1', 'Mozilla/5.0'),
(3, 'create', 'item', 2, 'Item created: Sweater Abu-abu', '127.0.0.1', 'Mozilla/5.0'),
(2, 'create', 'item', 3, 'Item created: Botol Minum Tupperware Biru', '127.0.0.1', 'Mozilla/5.0'),

-- Lost item creation activities
(4, 'create', 'lost_item', 1, 'Lost item report created: Jaket Hitam', '127.0.0.1', 'Mozilla/5.0'),
(5, 'create', 'lost_item', 3, 'Lost item report created: Botol Minum Biru', '127.0.0.1', 'Mozilla/5.0'),

-- Claim activities
(4, 'create', 'claim', 1, 'Claim created for item: Jaket Hitam Nike', '127.0.0.1', 'Mozilla/5.0'),
(5, 'create', 'claim', 2, 'Claim created for item: Botol Minum Tupperware Biru', '127.0.0.1', 'Mozilla/5.0'),
(4, 'create', 'claim', 3, 'Claim created for item: Kalkulator Casio FX-991ID Plus', '127.0.0.1', 'Mozilla/5.0'),

-- Claim verification activity
(2, 'approve', 'claim', 3, 'Claim approved: Deskripsi cocok, barang diserahkan', '127.0.0.1', 'Mozilla/5.0');

SET FOREIGN_KEY_CHECKS = 1;

-- ============================================
-- SUCCESS MESSAGE
-- ============================================
SELECT '✅ Database seeded successfully!' AS Status;
SELECT '👥 Users created: 8 (1 admin, 2 managers, 5 students)' AS Info;
SELECT '📦 Items created: 11 found items' AS Info;
SELECT '🔍 Lost items created: 7 reports' AS Info;
SELECT '📋 Claims created: 3 (1 approved, 2 pending)' AS Info;
SELECT '🔔 Notifications created: 6' AS Info;
SELECT '📝 Audit logs created: 11' AS Info;
SELECT '' AS Empty;
SELECT '🔐 Login Credentials:' AS Credentials;
SELECT 'Admin: admin@lostandfound.com / password123' AS Admin;
SELECT 'Manager: manager1@lostandfound.com / password123' AS Manager1;
SELECT 'Manager: manager2@lostandfound.com / password123' AS Manager2;
SELECT 'Student: ahmad@student.com / password123' AS Student;
SELECT '' AS Empty2;
SELECT '🚀 Ready to use! Start the server with: make run' AS NextStep;