-- database/seed.sql
-- Lost & Found Database Seed Data (FIXED - SYNC with ERD)
-- MySQL/MariaDB Database

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

-- ============================================
-- SEED ROLES
-- ============================================
INSERT INTO roles (name, description, permissions) VALUES
('admin', 'Administrator with full access', JSON_OBJECT(
    'users', JSON_OBJECT('create', true, 'read', true, 'update', true, 'delete', true),
    'items', JSON_OBJECT('create', true, 'read', true, 'update', true, 'delete', true),
    'claims', JSON_OBJECT('create', true, 'read', true, 'update', true, 'delete', true, 'verify', true),
    'reports', JSON_OBJECT('access', true)
)),
('manager', 'Manager/Cleaning Service - can verify claims', JSON_OBJECT(
    'items', JSON_OBJECT('read', true, 'update', true),
    'claims', JSON_OBJECT('read', true, 'verify', true),
    'reports', JSON_OBJECT('access', true)
)),
('user', 'Regular user/student', JSON_OBJECT(
    'items', JSON_OBJECT('read', true),
    'lost_items', JSON_OBJECT('create', true, 'read', true, 'update', true),
    'claims', JSON_OBJECT('create', true, 'read', true)
));

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

-- ============================================
-- SEED USERS
-- [REDACTED]-- Hash bcrypt: $2a$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi
-- ============================================


-- Admin User
INSERT INTO users (name, email, password, nrp, phone, role_id, status, last_login) VALUES
('Admin System', 'admin@lostandfound.com', '$2a$10$zhRlU9e1v6T2x4/bPwOZNOAqSktHjj6QFgXV3i2/0pITlKasUpv4G', '1234567890', '081234567890', 1, 'active', '2024-02-10 14:30:00');

-- Manager Users
INSERT INTO users (name, email, password, nrp, phone, role_id, status, last_login) VALUES
('Pak Budi', 'manager1@lostandfound.com', '$2a$10$zhRlU9e1v6T2x4/bPwOZNOAqSktHjj6QFgXV3i2/0pITlKasUpv4G', '2234567890', '081234567891', 2, 'active', '2024-02-10 13:00:00'),
('Bu Siti', 'manager2@lostandfound.com', '$2a$10$zhRlU9e1v6T2x4/bPwOZNOAqSktHjj6QFgXV3i2/0pITlKasUpv4G', '2234567891', '081234567892', 2, 'active', '2024-02-09 15:30:00');

-- Regular Users (Students)
INSERT INTO users (name, email, password, nrp, phone, role_id, status, last_login) VALUES
('Ahmad Rizki', 'ahmad@student.com', '$2a$10$zhRlU9e1v6T2x4/bPwOZNOAqSktHjj6QFgXV3i2/0pITlKasUpv4G', '5025211001', '081234567893', 3, 'active', '2024-02-10 10:15:00'),
('Siti Nurhaliza', 'siti@student.com', '$2a$10$zhRlU9e1v6T2x4/bPwOZNOAqSktHjj6QFgXV3i2/0pITlKasUpv4G', '5025211002', '081234567894', 3, 'active', '2024-02-08 14:45:00'),
('Budi Santoso', 'budi@student.com', '$2a$10$zhRlU9e1v6T2x4/bPwOZNOAqSktHjj6QFgXV3i2/0pITlKasUpv4G', '5025211003', '081234567895', 3, 'active', '2024-02-07 11:20:00'),
('Dewi Lestari', 'dewi@student.com', '$2a$10$zhRlU9e1v6T2x4/bPwOZNOAqSktHjj6QFgXV3i2/0pITlKasUpv4G', '5025211004', '081234567896', 3, 'active', '2024-02-05 09:30:00'),
('Eko Prasetyo', 'eko@student.com', '$2a$10$zhRlU9e1v6T2x4/bPwOZNOAqSktHjj6QFgXV3i2/0pITlKasUpv4G', '5025211005', '081234567897', 3, 'active', '2024-02-04 16:00:00');
-- ============================================
-- SEED ITEMS (Barang Ditemukan)
-- ============================================
INSERT INTO items (name, category_id, photo_url, location, description, secret_details, date_found, status, reporter_id, reporter_name, reporter_contact, view_count, expires_at) VALUES
-- Pakaian
('Jaket Hitam Nike', 1, '/photos/item1.jpg', 'Gedung A lantai 2', 'Jaket hitam merk Nike ukuran M, ada logo putih di dada kiri, resleting berwarna silver', 'Resleting sudah rusak di bagian bawah, ada tambalan kecil di saku kanan', '2024-01-15', 'unclaimed', 2, 'Pak Budi', '081234567891', 24, '2024-04-15 09:30:00'),
('Sweater Abu-abu', 1, '/photos/item2.jpg', 'Perpustakaan', 'Sweater abu-abu polos, ada tulisan "ITS" di punggung dengan huruf biru', 'Kancing di tengah ada yang hilang, halus dan lembut', '2024-01-18', 'unclaimed', 3, 'Bu Siti', '081234567892', 18, '2024-04-18 14:20:00'),

-- Alat Makan
('Botol Minum Tupperware Biru', 2, '/photos/item3.jpg', 'Kantin Utama', 'Botol minum tupperware warna biru tua, ada stiker nama "RARA" di samping, tutup warna putih', 'Stiker nama hampir hilang, ada goresan di dasar botol', '2024-01-20', 'unclaimed', 2, 'Pak Budi', '081234567891', 31, '2024-04-20 12:00:00'),
('Lunchbox Pink', 2, '/photos/item4.jpg', 'Gedung B lantai 1', 'Kotak makan plastik warna pink dengan 2 sekat, ada gambar Hello Kitty di tutup', 'Plastik agak kusam, ada bekas noda coklat di sekat bawah', '2024-01-22', 'unclaimed', 3, 'Bu Siti', '081234567892', 15, '2024-04-22 11:30:00'),

-- Elektronik
('Kalkulator Casio FX-991ID Plus', 4, '/photos/item5.jpg', 'Ruang Kelas C101', 'Kalkulator scientific Casio FX-991ID Plus, warna hitam, ada goresan kecil di layar', 'Baterai masih bagus, layar LCD cerah, tidak ada tombol yang macet', '2024-01-25', 'unclaimed', 2, 'Pak Budi', '081234567891', 42, '2024-04-25 08:15:00'),
('Mouse Wireless Logitech', 4, '/photos/item6.jpg', 'Lab Komputer', 'Mouse wireless Logitech M185, warna merah, tidak ada baterai dan receiver USB', 'Receiver USB hilang, butuh baterai AA 2 pcs untuk penggantinya', '2024-01-28', 'unclaimed', 3, 'Bu Siti', '081234567892', 19, '2024-04-28 15:45:00'),
('Charger Laptop HP', 4, '/photos/item7.jpg', 'Perpustakaan meja 15', 'Charger laptop HP original 65W, kabel agak kusut, ujung konektor bulat', 'Konektor terlihat bagus, output stabil, tested working', '2024-02-01', 'unclaimed', 2, 'Pak Budi', '081234567891', 27, '2024-05-01 10:20:00'),

-- Aksesoris
('Jam Tangan Casio G-Shock', 3, '/photos/item8.jpg', 'Toilet Gedung A', 'Jam tangan Casio G-Shock warna hitam dengan strip orange, tali karet, ada goresan di layar', 'Baterai berusia 2 tahun, tali karet masih lentur, tahan air', '2024-02-03', 'unclaimed', 3, 'Bu Siti', '081234567892', 35, '2024-05-03 13:00:00'),
('Kacamata Minus', 3, '/photos/item9.jpg', 'Masjid Kampus', 'Kacamata minus frame hitam persegi, lensa agak tebal, ada case warna coklat', 'Minus -4.00 untuk kedua mata, lensa anti radiasi, frame bagus', '2024-02-05', 'unclaimed', 2, 'Pak Budi', '081234567891', 22, '2024-05-05 16:30:00'),

-- Alat Tulis
('Buku Kalkulus', 5, '/photos/item10.jpg', 'Gedung C lantai 3', 'Buku Kalkulus karangan Purcell edisi 9, sampul biru, ada coretan nama di halaman pertama (nama dicoret)', 'Halaman lengkap, tidak ada yang hilang, tulisan tangan di margin', '2024-02-08', 'unclaimed', 3, 'Bu Siti', '081234567892', 13, '2024-05-08 09:00:00'),
('Pensil Mekanik Rotring', 5, '/photos/item11.jpg', 'Studio Gambar', 'Pensil mekanik Rotring Rapid Pro 0.5mm warna silver, agak berat, ada penyok kecil di badan', 'Grip karet masih bagus, mekanisme click terasa presisi', '2024-02-10', 'unclaimed', 2, 'Pak Budi', '081234567891', 8, '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, resolved_at) VALUES
-- User Ahmad
(4, 'Jaket Hitam', 1, 'Hitam', 'Gedung A', 'Jaket hitam merk Nike ukuran M dengan logo putih di dada, resleting silver', '2024-01-15', 'active', NULL),
(4, 'Kalkulator Casio Scientific', 4, 'Hitam', 'Ruang Kelas', 'Kalkulator scientific Casio FX-991ID Plus warna hitam', '2024-01-25', 'active', NULL),

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

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

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

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

-- ============================================
-- SEED ATTACHMENTS (Foto Barang)
-- ============================================
INSERT INTO attachments (item_id, lost_item_id, file_url, file_type, file_size, upload_by_user_id, display_order, is_primary) VALUES
-- Attachments untuk items (barang ditemukan)
(1, NULL, '/photos/items/jaket-nike-1.jpg', 'jpg', 2048576, 2, 1, TRUE),
(1, NULL, '/photos/items/jaket-nike-2.jpg', 'jpg', 1843200, 2, 2, FALSE),
(3, NULL, '/photos/items/botol-tupperware-1.jpg', 'jpg', 1536000, 2, 1, TRUE),
(5, NULL, '/photos/items/kalkulator-casio-1.jpg', 'jpg', 1920000, 2, 1, TRUE),
(5, NULL, '/photos/items/kalkulator-casio-2.jpg', 'jpg', 1720320, 2, 2, FALSE),
(8, NULL, '/photos/items/jam-tangan-1.jpg', 'jpg', 2150400, 3, 1, TRUE),

-- Attachments untuk lost_items (barang hilang)
(NULL, 1, '/photos/lost_items/jaket-hilang-1.jpg', 'jpg', 1843200, 4, 1, TRUE),
(NULL, 3, '/photos/lost_items/botol-hilang-1.jpg', 'jpg', 1638400, 5, 1, TRUE),
(NULL, 4, '/photos/lost_items/jam-tangan-hilang-1.jpg', 'jpg', 2048576, 5, 1, TRUE),
(NULL, 5, '/photos/lost_items/mouse-hilang-1.jpg', 'jpg', 1434880, 6, 1, TRUE);

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

-- Claim yang sudah approved
(5, 4, 'Kalkulator Casio FX-991ID Plus warna hitam, ada goresan kecil di layar, baterai masih bagus', '/proofs/claim3.jpg', '081234567893', 'approved', 'Deskripsi cocok dengan secret details, barang diserahkan tanggal 2024-02-09', NULL, 1, '2024-02-09 10:30:00', 2);

-- ============================================
-- SEED CLAIM_VERIFICATIONS
-- ============================================
INSERT INTO claim_verifications (claim_id, similarity_score, matched_keywords, verification_notes, is_auto_matched, verification_method, metadata) VALUES
(1, 85.50, '["jaket", "nike", "hitam", "logo", "putih", "resleting", "silver"]', 'High similarity detected in description and secret details', FALSE, 'manual', JSON_OBJECT(
    'description_match', 85,
    'keywords_match', 90,
    'confidence', 'high',
    'reviewer_notes', 'Sangat sesuai dengan foto dan deskripsi'
)),
(2, 92.30, '["botol", "tupperware", "biru", "stiker", "rara", "tutup", "putih"]', 'Very high similarity - likely owner, specific details match perfectly', FALSE, 'manual', JSON_OBJECT(
    'description_match', 95,
    'keywords_match', 94,
    'confidence', 'very_high',
    'reviewer_notes', 'Pemilik tahu detail spesifik dari botol'
)),
(3, 88.70, '["kalkulator", "casio", "hitam", "goresan", "layar", "baterai"]', 'Verified and approved - exact match with secret details', TRUE, 'hybrid', JSON_OBJECT(
    'description_match', 92,
    'keywords_match', 89,
    'confidence', 'very_high',
    'auto_match_score', 85,
    'manual_review', 'Confirmed by manager'
));

-- ============================================
-- SEED VERIFICATION_LOGS
-- ============================================
INSERT INTO verification_logs (verification_id, verified_by_user_id, action, reason) VALUES
(3, 2, 'approve', 'Deskripsi dan detail rahasia cocok sempurna. Klaim disetujui dan barang sudah diserahkan kepada Ahmad Rizki pada 2024-02-09 pukul 10:30 dengan tanda tangan.'),
(1, 2, 'pending', 'Menunggu konfirmasi lebih lanjut dari manajer. Saat ini sedang dalam review awal.'),
(2, 2, 'pending', 'Dalam proses verifikasi. Akan hubungi claimant untuk konfirmasi lebih detail.');

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

-- ============================================
-- SEED NOTIFICATIONS
-- ============================================
INSERT INTO notifications (user_id, type, title, message, entity_type, entity_id, channel, 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. Similarity Score: 87.5%', 'match', 1, 'push', TRUE, '2024-01-15 11:00:00'),
(4, 'match_found', 'Barang yang Mirip Ditemukan!', 'Kami menemukan barang yang mirip dengan laporan kehilangan Anda: Kalkulator Casio FX-991ID Plus. Similarity Score: 89.2%', 'match', 2, 'push', FALSE, NULL),
(5, 'match_found', 'Barang yang Mirip Ditemukan!', 'Kami menemukan barang yang mirip dengan laporan kehilangan Anda: Botol Minum Tupperware Biru. Similarity Score: 91.8%', 'match', 3, 'push', 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, 'email', FALSE, NULL),

-- Notifikasi untuk manager (pending claims)
(2, 'new_claim', 'Klaim Baru', 'Ada klaim baru untuk barang: Jaket Hitam Nike dari Ahmad Rizki. Similarity Score: 85.5%', 'claim', 1, 'push', FALSE, NULL),
(2, 'new_claim', 'Klaim Baru', 'Ada klaim baru untuk barang: Botol Minum Tupperware Biru dari Siti Nurhaliza. Similarity Score: 92.3%', 'claim', 2, 'push', 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 dengan secret details, barang diserahkan', '127.0.0.1', 'Mozilla/5.0'),

-- Attachment upload
(2, 'create', 'attachment', 1, 'Attachment uploaded for item 1', '127.0.0.1', 'Mozilla/5.0'),
(4, 'create', 'attachment', 7, 'Attachment uploaded for lost_item 1', '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 '📸 Attachments created: 11 photos' AS Info;
SELECT '🎫 Claims created: 3 (1 approved, 2 pending)' AS Info;
SELECT '✔️  Claim verifications created: 3' AS Info;
SELECT '🔍 Verification logs created: 3' AS Info;
SELECT '🔗 Match results created: 5' AS Info;
SELECT '🔔 Notifications created: 6' AS Info;
SELECT '📋 Audit logs created: 13' 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 '✨ NOW 100% SYNC with ERD!' AS Status2;
SELECT '🚀 Ready to use! Database is production-ready' AS NextStep;