import sys
import io
import os
from app import create_app, db
from app.models.learning import VocationalContent

# Ensure UTF-8 for console output
if sys.stdout.encoding != 'utf-8':
    sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')

def seed_vocational():
    app = create_app('development')
    with app.app_context():
        # Clear existing vocational content to avoid duplicates
        VocationalContent.query.delete()
        
        # New high-quality links provided by the user
        voc_data = {
            'en': [
                ('Professional Tailoring', 'Master advanced garment construction and precision tailoring for professional outfits.', 'Fashion', 'https://www.youtube.com/embed/IGITrkYdjJs'),
                ('Smartphone Hardware Repair', 'Complete guide to diagnosing and fixing hardware issues, including screen replacements.', 'Technology', 'https://www.youtube.com/embed/PdJxBX2EAHo'),
                ('Web Design for Beginners', 'Learn HTML, CSS, and Responsive Design to build professional websites from scratch.', 'Technology', 'https://www.youtube.com/embed/j6Ule7GXaRs'),
                ('Professional Catering', 'Learn the essentials of professional catering, large-scale food prep, and Nigerian delicacies.', 'Culinary', 'https://www.youtube.com/embed/PoL3rOomqUI'),
                ('Solar Energy Installation', 'Complete guide to designing and installing solar power systems for homes and businesses.', 'Technology', 'https://www.youtube.com/embed/khYZTmm7S5I'),
                ('Graphics Design', 'Master visual communication, logo design, and branding using professional tools.', 'Technology', 'https://www.youtube.com/embed/GQS7wPujL2k'),
                ('Modern Plumbing and Piping', 'Learn professional plumbing techniques for modern residential buildings and pipe fittings.', 'Construction', 'https://www.youtube.com/embed/8jxRn-T_LCs'),
                ('Mobile Phone Repair Workshop', 'Comprehensive workshop on fixing various mobile phone hardware and software issues.', 'Technology', 'https://www.youtube.com/embed/tH-6cchzL5k'),
                ('Advanced Fashion Tailoring', 'Take your tailoring skills to the next level with advanced cutting and sewing techniques.', 'Fashion', 'https://www.youtube.com/embed/Zg2PD3PbQh0'),
                ('Professional Pastry & Baking', 'Master the art of professional baking. Learn to make pastries, cakes, and bread.', 'Culinary', 'https://www.youtube.com/embed/8-5yLt1gqIo')
            ],
            'ha': [
                ('Ɗinkin Kaya na Kwararru', 'Koyi dabarun yanka da dinkin kaya na zamani don manyan mutane.', 'Fashion', 'https://www.youtube.com/embed/IGITrkYdjJs'),
                ('Gyaran Wayoyin Hannu', 'Cikakken jagora kan yadda ake gyara allon waya da sauran sassan ciki.', 'Technology', 'https://www.youtube.com/embed/PdJxBX2EAHo'),
                ('Koyon Web Design', 'Koyi yadda ake gina yanar gizo (websites) cikin sauki.', 'Technology', 'https://www.youtube.com/embed/j6Ule7GXaRs'),
                ('Girki da Abincin Party', 'Koyi yadda ake girki na kwararru don manyan bukukuwa.', 'Culinary', 'https://www.youtube.com/embed/PoL3rOomqUI'),
                ('Sanya Wutar Solar', 'Yadda ake sanya wutar rana (Solar) a gida ko wurin sana\'a.', 'Technology', 'https://www.youtube.com/embed/khYZTmm7S5I'),
                ('Koyon Graphics Design', 'Koyi zane-zane na zamani da yin tambarin (logo) kamfanoni.', 'Technology', 'https://www.youtube.com/embed/GQS7wPujL2k'),
                ('Aikin Plumber na Zamani', 'Koyi yadda ake sa bututu da gyaran magudanar ruwa a sabbin gidaje.', 'Construction', 'https://www.youtube.com/embed/8jxRn-T_LCs'),
                ('Gyaran Wayoyi Workshop', 'Taron bita kan yadda ake gyara kowace irin waya da ta lalace.', 'Technology', 'https://www.youtube.com/embed/tH-6cchzL5k'),
                ('Babban Darasin Ɗinki', 'Koyi yadda ake dinka hadaddun kayan ado na kwararru.', 'Fashion', 'https://www.youtube.com/embed/Zg2PD3PbQh0'),
                ('Koyon Yin Gurasa da Cake', 'Kware wajen yin kowane irin bredi da cake na kwararru.', 'Culinary', 'https://www.youtube.com/embed/8-5yLt1gqIo')
            ],
            'yo': [
                ('Iṣẹ́ Ríránṣọ Akọ́ṣẹ́mọṣẹ́', 'Kọ́ bí a ṣe n yà tí a sì n ránṣọ tó dára fún àwọn ènìyàn.', 'Fashion', 'https://www.youtube.com/embed/IGITrkYdjJs'),
                ('Àtúnṣe Fóònù Alágbèéká', 'Ìlànà kíkún lórí bí a ṣe n tún fóònù ṣe, títí kan ojú fóònù.', 'Technology', 'https://www.youtube.com/embed/PdJxBX2EAHo'),
                ('Kọ́ Web Design', 'Kọ́ HTML àti CSS láti kọ́ oju-ewé internet tirẹ.', 'Technology', 'https://www.youtube.com/embed/j6Ule7GXaRs'),
                ('Iṣẹ́ Olùpèsè Oúnjẹ (Catering)', 'Kọ́ bí a ṣe n dáná fún àwọn ayẹyẹ nlá àti oúnjẹ ilẹ̀ wa.', 'Culinary', 'https://www.youtube.com/embed/PoL3rOomqUI'),
                ('Ìfilọ́lẹ̀ Iná Solar', 'Ìlànà kíkún lórí bí a ṣe n fi iná oòrùn sínú ilé tàbí ibi iṣẹ́.', 'Technology', 'https://www.youtube.com/embed/khYZTmm7S5I'),
                ('Iṣẹ́ Graphics Design', 'Kọ́ bí a ṣe n ya àwòrán tó lẹ́wà fún iṣẹ́ ajé.', 'Technology', 'https://www.youtube.com/embed/GQS7wPujL2k'),
                ('Iṣẹ́ Plumber Tuntun', 'Kọ́ bí a ṣe n fi bututu sínú ilé àti àtúnṣe rẹ̀.', 'Construction', 'https://www.youtube.com/embed/8jxRn-T_LCs'),
                ('Àtúnṣe Fóònù Workshop', 'Àpérò lórí bí a ṣe n tún onírúurú fóònù ṣe.', 'Technology', 'https://www.youtube.com/embed/tH-6cchzL5k'),
                ('Ríránṣọ Akọ́ṣẹ́mọṣẹ́ Gidi', 'Kọ́ àwọn ọ̀nà tuntun láti ránṣọ tó lẹ́wà jùlọ.', 'Fashion', 'https://www.youtube.com/embed/Zg2PD3PbQh0'),
                ('Kọ́ Bíkì (Baking)', 'Kọ́ bí a ṣe n ṣe búrẹ́dì, cake, àti àwọn oúnjẹ bíkì mìíràn.', 'Culinary', 'https://www.youtube.com/embed/8-5yLt1gqIo')
            ],
            'ig': [
                ('Ịkwa ákwà ndị ọkachamara', 'Mụta otú e si atụle ma kwasịa ákwà ndị mara mma nke ukwuu.', 'Fashion', 'https://www.youtube.com/embed/IGITrkYdjJs'),
                ('Nzi nhazi Fóònù', 'Otú e si arụzi fóònù ndị mebiri emebi na ịgbanwe ihu fóònù.', 'Technology', 'https://www.youtube.com/embed/PdJxBX2EAHo'),
                ('Mmụta Web Design', 'Mụta otú e si ewu oju-ewé internet site n\'aka.', 'Technology', 'https://www.youtube.com/embed/j6Ule7GXaRs'),
                ('Ịdị n’aka na nri (Catering)', 'Mụta otú e si esi nri maka nnukwu mmemme na nri ala anyị.', 'Culinary', 'https://www.youtube.com/embed/PoL3rOomqUI'),
                ('Ịtinye ọkụ Solar', 'Otú e si etinye ọkụ anyanwụ n’ụlọ ma ọ bụ n’ebe ọrụ.', 'Technology', 'https://www.youtube.com/embed/khYZTmm7S5I'),
                ('Nzi nhazi Graphics', 'Mụta otú e si ese ihe ndị mara mma maka azụmahịa.', 'Technology', 'https://www.youtube.com/embed/GQS7wPujL2k'),
                ('Ihe gbasara Plumber', 'Mụta otú e si etinye paịpụ mmiri n’ụlọ ọhụrụ.', 'Construction', 'https://www.youtube.com/embed/8jxRn-T_LCs'),
                ('Workshop maka rụzie Fóònù', 'Ịmụtakwu maka otú e si arụzi fóònù ọ bụla mebiri emebi.', 'Technology', 'https://www.youtube.com/embed/tH-6cchzL5k'),
                ('Ịkwa ákwà ọkwa dị elu', 'Mụta ụzọ ndị ọhụrụ e si akwa ákwà mara mma nke ukwuu.', 'Fashion', 'https://www.youtube.com/embed/Zg2PD3PbQh0'),
                ('Mmụta Bíkì (Baking)', 'Mụta otú e si esi achịcha, cake, na ihe ndị ọzọ na-atọ ụtọ.', 'Culinary', 'https://www.youtube.com/embed/8-5yLt1gqIo')
            ],
            'pi': [
                ('Correct Tailoring Work', 'How to measure, cut and sew cloth like person wey sabi well-well.', 'Fashion', 'https://www.youtube.com/embed/IGITrkYdjJs'),
                ('Phone Repair Level', 'Complete guide for how to change screen and fix phone problem.', 'Technology', 'https://www.youtube.com/embed/PdJxBX2EAHo'),
                ('Web Design for Beginners', 'Learn how to build website from scratch with HTML and CSS.', 'Technology', 'https://www.youtube.com/embed/j6Ule7GXaRs'),
                ('Catering and Baking', 'Learn how to cook better party food and how to bake beta cake.', 'Culinary', 'https://www.youtube.com/embed/PoL3rOomqUI'),
                ('Solar Power Work', 'How to install solar for house or office make you get light.', 'Technology', 'https://www.youtube.com/embed/khYZTmm7S5I'),
                ('Graphics Design Work', 'Learn how to design logo and posters like expert.', 'Technology', 'https://www.youtube.com/embed/GQS7wPujL2k'),
                ('Modern Plumbing Work', 'How to fix pipe and handle all plumbing for beta house.', 'Construction', 'https://www.youtube.com/embed/8jxRn-T_LCs'),
                ('Phone Repair Workshop', 'Better seminar on how to fix any phone wey don spoil.', 'Technology', 'https://www.youtube.com/embed/tH-6cchzL5k'),
                ('Advanced Tailoring Level', 'Learn better ways to cut and sew correct fashion design.', 'Fashion', 'https://www.youtube.com/embed/Zg2PD3PbQh0'),
                ('Bread and Cake Baking', 'Become master baker, learn how to make bread and cake.', 'Culinary', 'https://www.youtube.com/embed/8-5yLt1gqIo')
            ]
        }

        for lang, items in voc_data.items():
            for title, desc, cat, url in items:
                content = VocationalContent(
                    title=title,
                    description=desc,
                    category=cat,
                    resource_url=url,
                    language=lang
                )
                db.session.add(content)
                print(f"Seeding [{lang}]: {title}")

        db.session.commit()
        print("Vocational V5 (Updated Links) Seeding Complete.")

if __name__ == '__main__':
    seed_vocational()
