CREATE EXTENSION IF NOT EXISTS pgcrypto;


INSERT INTO users (
    id,
    first_name,
    last_name,
    gender,
    birth_day,
    email,
    phone_number,
    role,
    password,
    age_group,
    education_level,
    country,
    region,
    knowledge_level,
    nick_name,
    occupation,
    learning_goal,
    language_goal,
    language_challange,
    favourite_topic,
    initial_assessment_completed,
    email_verified,
    phone_verified,
    status,
    last_login,
    profile_completed,
    profile_picture_url,
    preferred_language,
    created_at,
    updated_at
)
VALUES
(
    10,
    'Demo',
    'Student',
    'Male',
    '2000-01-01',
    'student10@yimaru.com',
    NULL,
    'USER',
    crypt('password@123', gen_salt('bf'))::bytea,
    '25_34',
    'Bachelor',
    'Ethiopia',
    'Addis Ababa',
    'BEGINNER',
    'Demo',
    'Student',
    'Learn programming',
    'English',
    'Grammar',
    'Technology',
    FALSE,
    TRUE,
    FALSE,
    'ACTIVE',
    NULL,
    FALSE,
    NULL,
    'en',
    CURRENT_TIMESTAMP,
    NULL
),
(
    11,
    'System',
    'Admin',
    'Female',
    '1995-01-01',
    'admin@yimaru.com',
    '0911001100',
    'ADMIN',
    crypt('password@123', gen_salt('bf'))::bytea,
    '35_44',
    'Master',
    'Ethiopia',
    'Addis Ababa',
    'ADVANCED',
    'SysAdmin',
    'Administrator',
    'Manage system',
    'English',
    'Writing',
    'Management',
    TRUE,
    TRUE,
    TRUE,
    'ACTIVE',
    NULL,
    TRUE,
    NULL,
    'en',
    CURRENT_TIMESTAMP,
    NULL
),
(
    12,
    'Support',
    'Agent',
    'Female',
    '1998-01-01',
    'support@yimaru.com',
    '0911223344',
    'SUPPORT',
    crypt('password@123', gen_salt('bf'))::bytea,
    '55_PLUS',
    'Diploma',
    'Ethiopia',
    'Addis Ababa',
    'INTERMEDIATE',
    'Support',
    'Agent',
    'Assist users',
    'English',
    'Conversation',
    'Customer Service',
    TRUE,
    TRUE,
    TRUE,
    'ACTIVE',
    NULL,
    TRUE,
    NULL,
    'en',
    CURRENT_TIMESTAMP,
    NULL
)
ON CONFLICT (id) DO NOTHING;

-- ======================================================
-- Global Settings (LMS)
-- ======================================================
INSERT INTO global_settings (key, value)
VALUES
    ('platform_name', 'Yimaru LMS'),
    ('default_language', 'en'),
    ('allow_self_signup', 'true'),
    ('otp_expiry_minutes', '5'),
    ('certificate_enabled', 'true'),
    ('max_courses_per_instructor', '50')
ON CONFLICT (key) DO NOTHING;
-- ======================================================

-- ======================================================
-- Questions - Level A2 (EASY)
-- ======================================================

INSERT INTO questions (id, question_text, question_type, difficulty_level, points, status)
VALUES
(1, 'What would you say to greet someone before lunchtime?', 'MCQ', 'EASY', 1, 'PUBLISHED'),
(2, 'Which question is correct to ask about your routine?', 'MCQ', 'EASY', 1, 'PUBLISHED'),
(3, 'She ___ like pizza.', 'MCQ', 'EASY', 1, 'PUBLISHED'),
(4, 'I usually go to school and start class ____ eight o''clock.', 'MCQ', 'EASY', 1, 'PUBLISHED'),
(5, 'Someone says, "Here is the book you asked for." What is the best response?', 'MCQ', 'EASY', 1, 'PUBLISHED')
ON CONFLICT (id) DO NOTHING;

INSERT INTO question_options (question_id, option_text, option_order, is_correct)
VALUES
-- Q1
(1, 'Good morning.', 1, TRUE),
(1, 'How do you do?', 2, FALSE),
(1, 'Good afternoon.', 3, FALSE),
(1, 'Goodbye.', 4, FALSE),

-- Q2
(2, 'What time you wake up?', 1, FALSE),
(2, 'What time do you wake up?', 2, TRUE),
(2, 'What time are you wake up?', 3, FALSE),
(2, 'What time waking you?', 4, FALSE),

-- Q3
(3, 'do not', 1, FALSE),
(3, 'not', 2, FALSE),
(3, 'is not', 3, FALSE),
(3, 'does not', 4, TRUE),

-- Q4
(4, 'about', 1, FALSE),
(4, 'on', 2, FALSE),
(4, 'at', 3, TRUE),
(4, 'in', 4, FALSE),

-- Q5
(5, 'Never mind.', 1, FALSE),
(5, 'Really?', 2, FALSE),
(5, 'What a pity!', 3, FALSE),
(5, 'Thank you.', 4, TRUE);

-- ======================================================
-- Questions - Level B1 (MEDIUM)
-- ======================================================

INSERT INTO questions (id, question_text, question_type, difficulty_level, points, status)
VALUES
(6, 'How do you introduce your friend to another person?', 'MCQ', 'MEDIUM', 1, 'PUBLISHED'),
(7, 'How would you ask for the price of an item in a shop?', 'MCQ', 'MEDIUM', 1, 'PUBLISHED'),
(8, 'Which sentence correctly gives simple directions?', 'MCQ', 'MEDIUM', 1, 'PUBLISHED'),
(9, 'The watch shows 10:50, but the real time is 10:45. What can you say?', 'MCQ', 'MEDIUM', 1, 'PUBLISHED'),
(10, 'Which instruction is correct when giving directions?', 'MCQ', 'MEDIUM', 1, 'PUBLISHED')
ON CONFLICT (id) DO NOTHING;

INSERT INTO question_options (question_id, option_text, option_order, is_correct)
VALUES
-- Q6
(6, 'Hello, my name is Samson.', 1, FALSE),
(6, 'Good morning. Nice to meet you.', 2, FALSE),
(6, 'Let me introduce myself to my friend.', 3, FALSE),
(6, 'This is my friend, Samson.', 4, TRUE),

-- Q7
(7, 'How many are these?', 1, FALSE),
(7, 'What is this?', 2, FALSE),
(7, 'How much is this?', 3, TRUE),
(7, 'Where is the nearest shop?', 4, FALSE),

-- Q8
(8, 'Thank you very much for asking.', 1, FALSE),
(8, 'Turn left and walk two blocks.', 2, TRUE),
(8, 'Why don''t you eat out.', 3, FALSE),
(8, 'Take the bus to the park.', 4, FALSE),

-- Q9
(9, 'My watch is slow.', 1, TRUE),
(9, 'My watch is late.', 2, FALSE),
(9, 'My watch is fast.', 3, FALSE),
(9, 'My watch is early.', 4, FALSE),

-- Q10
(10, 'Turn left.', 1, TRUE),
(10, 'Turn on left.', 2, FALSE),
(10, 'Turn left side.', 3, FALSE),
(10, 'Turn to straight.', 4, FALSE);

-- ======================================================
-- Questions - Level B2 (HARD)
-- ======================================================

INSERT INTO questions (id, question_text, question_type, difficulty_level, points, status)
VALUES
(11, 'What is the most polite way to ask to speak to someone on the phone?', 'MCQ', 'HARD', 1, 'PUBLISHED'),
(12, 'How do you correctly state the age of a person who is 30 years old?', 'MCQ', 'HARD', 1, 'PUBLISHED'),
(13, 'When asking for help with a new Yimaru App feature, which option is most appropriate?', 'MCQ', 'HARD', 1, 'PUBLISHED'),
(14, 'Which word has the unvoiced "th" sound?', 'MCQ', 'HARD', 1, 'PUBLISHED'),
(15, 'Which sentence sounds like a warning, not friendly advice?', 'MCQ', 'HARD', 1, 'PUBLISHED'),
(16, 'What does this sentence mean? "I will definitely be there on time."', 'MCQ', 'HARD', 1, 'PUBLISHED')
ON CONFLICT (id) DO NOTHING;

INSERT INTO question_options (question_id, option_text, option_order, is_correct)
VALUES
-- Q11
(11, 'May I speak to Mr. Tesfaye, please?', 1, TRUE),
(11, 'Can I talk to Mr. Tesfaye?', 2, FALSE),
(11, 'Is Mr. Tesfaye there?', 3, FALSE),
(11, 'I want to talk to Mr. Tesfaye.', 4, FALSE),

-- Q12
(12, 'He is thirty years.', 1, FALSE),
(12, 'He has thirty years.', 2, FALSE),
(12, 'He has thirty years old.', 3, FALSE),
(12, 'He is thirty.', 4, TRUE),

-- Q13
(13, 'Are you familiar with how this feature works?', 1, FALSE),
(13, 'Could you walk me through how this feature works?', 2, TRUE),
(13, 'I believe I understand how this feature works.', 3, FALSE),
(13, 'I''ve tried similar features before.', 4, FALSE),

-- Q14
(14, 'That', 1, FALSE),
(14, 'They', 2, FALSE),
(14, 'These', 3, FALSE),
(14, 'Three', 4, TRUE),

-- Q15
(15, 'You might want to plan your time better.', 1, FALSE),
(15, 'If I were you, I''d start earlier.', 2, FALSE),
(15, 'You''d better meet the deadline this time.', 3, TRUE),
(15, 'Why don''t you try using a planner?', 4, FALSE),

-- Q16
(16, 'The speaker is unsure about arriving.', 1, FALSE),
(16, 'The speaker is promising to arrive on time.', 2, TRUE),
(16, 'The speaker might arrive late.', 3, FALSE),
(16, 'The speaker has already arrived.', 4, FALSE);

-- ======================================================
-- Initial Assessment Question Set
-- ======================================================

INSERT INTO question_sets (id, title, description, set_type, owner_type, status)
VALUES
(1, 'Initial Assessment', 'Default initial assessment for new users', 'INITIAL_ASSESSMENT', 'STANDALONE', 'PUBLISHED')
ON CONFLICT (id) DO NOTHING;

INSERT INTO question_set_items (set_id, question_id, display_order)
VALUES
(1, 1, 1), (1, 2, 2), (1, 3, 3), (1, 4, 4), (1, 5, 5),
(1, 6, 6), (1, 7, 7), (1, 8, 8), (1, 9, 9), (1, 10, 10),
(1, 11, 11), (1, 12, 12), (1, 13, 13), (1, 14, 14), (1, 15, 15), (1, 16, 16)
ON CONFLICT (set_id, question_id) DO NOTHING;

-- ======================================================
-- Course Management Seed Data
-- ======================================================

-- Course Categories
INSERT INTO course_categories (name, is_active, created_at) VALUES
('Programming', TRUE, CURRENT_TIMESTAMP),
('Data Science', TRUE, CURRENT_TIMESTAMP),
('Web Development', TRUE, CURRENT_TIMESTAMP);

-- Courses
INSERT INTO courses (category_id, title, description, thumbnail, is_active) VALUES
(1, 'Python Programming Fundamentals', 'Learn Python from basics to advanced concepts', 'https://example.com/thumbnails/python.jpg', TRUE),
(1, 'JavaScript for Beginners', 'Master JavaScript programming language', 'https://example.com/thumbnails/javascript.jpg', TRUE),
(1, 'Advanced Java Development', 'Deep dive into Java enterprise development', 'https://example.com/thumbnails/java.jpg', TRUE),
(2, 'Data Analysis with Python', 'Learn data manipulation and analysis using pandas', 'https://example.com/thumbnails/data-analysis.jpg', TRUE),
(2, 'Machine Learning Basics', 'Introduction to machine learning algorithms', 'https://example.com/thumbnails/ml.jpg', TRUE),
(3, 'Full Stack Web Development', 'Complete guide to modern web development', 'https://example.com/thumbnails/fullstack.jpg', TRUE),
(3, 'React.js Masterclass', 'Build dynamic user interfaces with React', 'https://example.com/thumbnails/react.jpg', TRUE);

-- Sub-courses (replacing Programs/Levels hierarchy)
INSERT INTO sub_courses (course_id, title, description, thumbnail, display_order, level, is_active) VALUES
-- Python Programming Fundamentals sub-courses
(1, 'Python Basics - Getting Started', 'Introduction to Python and basic syntax', NULL, 1, 'BEGINNER', TRUE),
(1, 'Python Basics - Data Types', 'Understanding Python data types and variables', NULL, 2, 'BEGINNER', TRUE),
(1, 'Python Intermediate - Functions', 'Writing and using functions in Python', NULL, 3, 'INTERMEDIATE', TRUE),
(1, 'Python Intermediate - Collections', 'Working with Python collections', NULL, 4, 'INTERMEDIATE', TRUE),
(1, 'Python Advanced - Best Practices', 'Advanced Python concepts and best practices', NULL, 5, 'ADVANCED', TRUE),

-- JavaScript sub-courses
(2, 'JavaScript Fundamentals', 'Core JavaScript concepts and syntax', NULL, 1, 'BEGINNER', TRUE),
(2, 'DOM Manipulation Basics', 'Working with the Document Object Model', NULL, 2, 'INTERMEDIATE', TRUE),

-- Java sub-courses
(3, 'Java Core Concepts', 'Essential Java programming principles', NULL, 1, 'BEGINNER', TRUE),
(3, 'Spring Framework Intro', 'Building enterprise applications with Spring', NULL, 2, 'ADVANCED', TRUE),

-- Data Science sub-courses
(4, 'Data Analysis Fundamentals', 'Learn data manipulation with pandas', NULL, 1, 'BEGINNER', TRUE),
(4, 'Advanced Data Analysis', 'Complex data transformations', NULL, 2, 'ADVANCED', TRUE),

-- Machine Learning sub-courses
(5, 'ML Basics', 'Introduction to machine learning concepts', NULL, 1, 'BEGINNER', TRUE),
(5, 'ML Algorithms', 'Understanding common ML algorithms', NULL, 2, 'INTERMEDIATE', TRUE),

-- Full Stack Web Development sub-courses
(6, 'Frontend Fundamentals', 'HTML, CSS, and JavaScript basics', NULL, 1, 'BEGINNER', TRUE),
(6, 'Backend Development', 'Server-side programming', NULL, 2, 'INTERMEDIATE', TRUE),

-- React.js sub-courses
(7, 'React Basics', 'Core React concepts and JSX', NULL, 1, 'BEGINNER', TRUE),
(7, 'React Advanced Patterns', 'Hooks, context, and performance', NULL, 2, 'ADVANCED', TRUE);

-- Sub-course Videos
INSERT INTO sub_course_videos (
    sub_course_id,
    title,
    description,
    video_url,
    duration,
    resolution,
    visibility,
    display_order,
    status
) VALUES
(1, 'Python Installation Guide', 'Installing Python', 'https://example.com/python-install.mp4', 900, '1080p', 'public', 1, 'PUBLISHED'),
(1, 'Your First Python Program', 'Writing and running your first Python script', 'https://example.com/python-hello.mp4', 1200, '1080p', 'public', 2, 'PUBLISHED'),
(2, 'Numbers and Math', 'Numeric types in Python', 'https://example.com/python-numbers.mp4', 1500, '720p', 'public', 1, 'PUBLISHED'),
(2, 'Strings in Python', 'Working with text data', 'https://example.com/python-strings.mp4', 1300, '1080p', 'public', 2, 'DRAFT'),
(3, 'Writing Functions', 'Creating reusable code with functions', 'https://example.com/python-functions.mp4', 1800, '1080p', 'public', 1, 'PUBLISHED');

-- Practice Question Sets (replacing practices table)
INSERT INTO question_sets (id, title, description, set_type, owner_type, owner_id, persona, status) VALUES
(2, 'Python Basics Assessment', 'Test Python basics', 'PRACTICE', 'SUB_COURSE', 1, 'beginner', 'PUBLISHED'),
(3, 'Data Types Practice', 'Practice Python data types', 'PRACTICE', 'SUB_COURSE', 2, 'beginner', 'PUBLISHED'),
(4, 'Functions Quiz', 'Assess function knowledge', 'PRACTICE', 'SUB_COURSE', 3, 'intermediate', 'DRAFT')
ON CONFLICT (id) DO NOTHING;

-- Practice Questions (using unified questions table)
INSERT INTO questions (id, question_text, question_type, tips, status)
VALUES
(17, 'What is the correct way to print "Hello World" in Python?', 'MCQ', 'Use print()', 'PUBLISHED'),
(18, 'Which is a valid Python variable name?', 'MCQ', 'Variables cannot start with numbers', 'PUBLISHED'),
(19, 'How do you convert "123" to an integer?', 'MCQ', 'Use int()', 'PUBLISHED'),
(20, 'How many times does range(3) loop run?', 'MCQ', 'Starts from zero', 'PUBLISHED')
ON CONFLICT (id) DO NOTHING;

-- Link practice questions to question sets
INSERT INTO question_set_items (set_id, question_id, display_order)
VALUES
(2, 17, 1), (2, 18, 2),
(3, 19, 1),
(4, 20, 1)
ON CONFLICT (set_id, question_id) DO NOTHING;

-- ======================================================
-- User Personas for Practice Sessions
-- Link existing users as personas to practice question sets
-- ======================================================

INSERT INTO question_set_personas (question_set_id, user_id, display_order)
VALUES
(2, 10, 1), (2, 11, 2),
(3, 12, 1),
(4, 10, 1), (4, 12, 2)
ON CONFLICT (question_set_id, user_id) DO NOTHING;

-- ======================================================
-- Team Members (Internal LMS Staff)
-- ======================================================

INSERT INTO team_members (
    id,
    first_name,
    last_name,
    email,
    phone_number,
    password,
    team_role,
    department,
    job_title,
    employment_type,
    hire_date,
    bio,
    status,
    email_verified,
    permissions,
    created_at
)
VALUES
(
    1,
    'Yared',
    'Yemane',
    'yared@yimaru.com',
    '0911001100',
    crypt('password@123', gen_salt('bf'))::bytea,
    'SUPER_ADMIN',
    'Engineering',
    'CTO',
    'full_time',
    '2024-01-01',
    'Platform super administrator with full system access.',
    'active',
    TRUE,
    '["*"]'::jsonb,
    CURRENT_TIMESTAMP
),
(
    2,
    'Admin',
    'User',
    'admin@yimaru.com',
    '0922001100',
    crypt('password@123', gen_salt('bf'))::bytea,
    'ADMIN',
    'Operations',
    'Operations Manager',
    'full_time',
    '2024-02-01',
    'Administrative staff managing day-to-day operations.',
    'active',
    TRUE,
    '["users.manage", "courses.manage", "settings.manage"]'::jsonb,
    CURRENT_TIMESTAMP
),
(
    3,
    'Content',
    'MANAGER',
    'content@yimaru.com',
    '0933001100',
    crypt('password@123', gen_salt('bf'))::bytea,
    'CONTENT_MANAGER',
    'Content',
    'Content Lead',
    'full_time',
    '2024-03-01',
    'Manages all course content and curriculum.',
    'active',
    TRUE,
    '["courses.manage", "courses.publish", "content.manage"]'::jsonb,
    CURRENT_TIMESTAMP
),
(
    4,
    'Support',
    'AGENT',
    'support-team@yimaru.com',
    '0944001100',
    crypt('password@123', gen_salt('bf'))::bytea,
    'SUPPORT_AGENT',
    'Support',
    'Customer Support Specialist',
    'full_time',
    '2024-03-15',
    'Handles customer inquiries and support tickets.',
    'active',
    TRUE,
    '["users.view", "tickets.manage", "support.manage"]'::jsonb,
    CURRENT_TIMESTAMP
),
(
    5,
    'INSTRUCTOR',
    'Demo',
    'instructor@yimaru.com',
    '0955001100',
    crypt('password@123', gen_salt('bf'))::bytea,
    'INSTRUCTOR',
    'Education',
    'Senior Instructor',
    'full_time',
    '2024-04-01',
    'Creates and manages course materials.',
    'active',
    TRUE,
    '["courses.create", "courses.edit", "students.view"]'::jsonb,
    CURRENT_TIMESTAMP
),
(
    6,
    'FINANCE',
    'Officer',
    'finance@yimaru.com',
    '0966001100',
    crypt('password@123', gen_salt('bf'))::bytea,
    'FINANCE',
    'Finance',
    'Finance Officer',
    'full_time',
    '2024-04-15',
    'Manages payments, subscriptions, and financial reports.',
    'active',
    TRUE,
    '["payments.manage", "subscriptions.manage", "reports.finance"]'::jsonb,
    CURRENT_TIMESTAMP
),
(
    7,
    'HR',
    'MANAGER',
    'hr@yimaru.com',
    '0977001100',
    crypt('password@123', gen_salt('bf'))::bytea,
    'HR',
    'Human Resources',
    'HR Manager',
    'full_time',
    '2024-05-01',
    'Manages team members and HR operations.',
    'active',
    TRUE,
    '["team.manage", "team.create", "team.delete"]'::jsonb,
    CURRENT_TIMESTAMP
),
(
    8,
    'Data',
    'Analyst',
    'analyst@yimaru.com',
    '0988001100',
    crypt('password@123', gen_salt('bf'))::bytea,
    'ANALYST',
    'Analytics',
    'Data Analyst',
    'contract',
    '2024-06-01',
    'Generates reports and analyzes platform metrics.',
    'active',
    TRUE,
    '["reports.view", "analytics.view", "users.view"]'::jsonb,
    CURRENT_TIMESTAMP
)
ON CONFLICT (id) DO NOTHING;
