# -*- coding: utf-8 -*-

# 1st-run initialisation
# designed to be called from Crontab's @reboot
# however this isn't reliable (doesn't work on Win32 Service) so still in models for now...

# Deployments can change settings live via appadmin

# Set deployment_settings.base.prepopulate to False in Production (to save 1x DAL hit every page)
if not deployment_settings.get_base_prepopulate() or db(db["s3_setting"].id > 0).count():
    populate = False
else:
    populate = True

if populate:

    # Themes
    tablename = "admin_theme"
    table = db[tablename]
    if not db(table.id > 0).count():
        table.insert(
            name = T("Sahana Blue"),
            logo = "img/sahanapy_logo.png",
            #header_background = "img/header_bg.png",
            #footer = "footer.html",
            col_background = "336699",
            col_menu = "0066cc",
            col_highlight = "0077aa",
            col_txt_background = "f3f6ff",
            col_txt_border = "c6d1f5",
            col_txt_underline = "003366",
            col_txt = "006699",
            col_input = "ffffcc",
            col_border_btn_out = "6699cc",
            col_border_btn_in = "4589ce",
            col_btn_hover = "3377bb",
        )
        table.insert(
            name = T("Sahana Green"),
            logo = "img/sahanapy_logo_green.png",
            #header_background = "img/header_bg.png",
            #footer = "footer.html",
            col_background = "337733",
            col_menu = "cc7722",
            col_highlight = "338833",
            col_txt_background = "f3f6ff",
            col_txt_border = "c6d1f5",
            col_txt_underline = "003366",
            col_txt = "006699",
            col_input = "ffffcc",
            col_border_btn_out = "6699cc",
            col_border_btn_in = "4589ce",
            col_btn_hover = "3377bb",
        )
        table.insert(
            # Needs work
            # - some colours need changing independently of each other
            # - logo size needs storing
            name = T("Sahana Steel"),
            logo = "img/sahanapy_logo_ideamonk.png",
            #header_background = "img/header_bg.png",
            #footer = "footer.html",
            col_background = "dbdbdb",
            col_menu = "0066cc",
            col_highlight = "0077aa",
            col_txt_background = "f3f6ff",
            col_txt_border = "c6d1f5",
            col_txt_underline = "003366",
            col_txt = "eeeeee",
            col_input = "ffffcc",
            col_border_btn_out = "c6d1f5",
            col_border_btn_in = "4589ce",
            col_btn_hover = "3377bb",
        )

    # Global Settings
    tablename = "s3_setting"
    table = db[tablename]
    # Ensure that the theme we defined is in the DB ready to be used as a FK
    db.commit()
    if not db(table.id > 0).count():
        table.insert(
            admin_name = T("Sahana Administrator").xml(),
            admin_email = "support@Not Set",
            admin_tel = T("Not Set").xml(),
            theme = 1
        )

    # Organisation Registry
    tablename = "org_cluster"
    table = db[tablename]
    if not db(table.id > 0).count():
        table.insert(
            abrv = T("Agriculture"),
            name = T("Agriculture")
        )
        table.insert(
            abrv = T("Camp"),
            name = T("Camp Coordination/Management")
        )
        table.insert(
            abrv = T("Recovery"),
            name = T("Early Recovery")
        )
        table.insert(
            abrv = T("Education"),
            name = T("Education")
        )
        table.insert(
            abrv = T("Shelter"),
            name = T("Emergency Shelter")
        )
        table.insert(
            abrv = T("Telecommunications"),
            name = T("Emergency Telecommunications")
        )
        table.insert(
            abrv = T("Health"),
            name = T("Health")
        )
        table.insert(
            abrv = T("Logistics"),
            name = T("Logistics")
        )
        table.insert(
            abrv = T("Nutrition"),
            name = T("Nutrition")
        )
        table.insert(
            abrv = T("Protection"),
            name = T("Protection")
        )
        table.insert(
            abrv = T("WASH"),
            name = T("Water Sanitation Hygiene")
        )
    tablename = "org_cluster_subsector"