package services

import (
	"cpone/models"
	dbx "cpone/package/database"
	"fmt"

	"go.uber.org/zap"
)

// Func get menu sidebar
func GetMenu() ([]models.Menu, error) {

	// dummyBreadcrumb := []Breadcrumb{
	// 	{
	// 		Name: "Dashboard",
	// 		Url:  "/client/dashboard",
	// 	},
	// 	{
	// 		Name: "Front Office",
	// 		Url:  "/client/usermanagement",
	// 	},
	// }

	dummyMenu := []models.Menu{
		// 1. Dashboard
		{
			ID:             "1",
			ParentMenuID:   "0",
			ParentMenuName: "Dashboard",
			ParentUrl:      "/client/md/dashboard",
			ParentIcon:     "",
			Children: []models.ChildrenMenu{
				{
					ChildrenParentID: "1",
					ChildrenMenuID:   "1",
					ChildrenMenuName: "Master User",
					ChildrenMenuURL:  "/client/md/user",
					// Breadcrumb: []Breadcrumb{
					// 	{
					// 		IDBreadcrumb: "1",
					// 		Title:        "Dashboard",
					// 		IsActive:     "Y",
					// 	},
					// },
				},
			},
		},

		// 2. Front Office
		{
			ID:             "2",
			ParentMenuID:   "1",
			ParentMenuName: "Front Office",
			ParentUrl:      "#",
			ParentIcon:     "",
			Children: []models.ChildrenMenu{
				{
					ChildrenParentID: "1",
					ChildrenMenuID:   "1",
					ChildrenMenuName: "Registrasi",
					ChildrenMenuURL:  "/fo/registrasi",
					// Breadcrumb: []Breadcrumb{
					// 	{
					// 		IDBreadcrumb: "1",
					// 		Title:        "Dashboard",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "2",
					// 		Title:        "Master",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "3",
					// 		Title:        "User",
					// 		IsActive:     "Y",
					// 	},
					// },
				},
			},
		},

		// 3. Station
		{
			ID:             "3",
			ParentMenuID:   "2",
			ParentMenuName: "Station",
			ParentUrl:      "#",
			ParentIcon:     "",
			Children: []models.ChildrenMenu{
				{
					ChildrenParentID: "2",
					ChildrenMenuID:   "1",
					ChildrenMenuName: "Sample Station",
					ChildrenMenuURL:  "/station/sample",
					// Breadcrumb: []Breadcrumb{
					// 	{
					// 		IDBreadcrumb: "1",
					// 		Title:        "Dashboard",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "2",
					// 		Title:        "Master",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "3",
					// 		Title:        "User",
					// 		IsActive:     "Y",
					// 	},
					// },
				},
			},
		},

		// 4. Management MCU
		{
			ID:             "4",
			ParentMenuID:   "3",
			ParentMenuName: "Management MCU",
			ParentUrl:      "#",
			ParentIcon:     "",
			Children: []models.ChildrenMenu{
				{
					ChildrenParentID: "3",
					ChildrenMenuID:   "1",
					ChildrenMenuName: "Setup MCU",
					ChildrenMenuURL:  "/mcu/setup",
					// Breadcrumb: []Breadcrumb{
					// 	{
					// 		IDBreadcrumb: "1",
					// 		Title:        "Dashboard",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "2",
					// 		Title:        "Master",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "3",
					// 		Title:        "User",
					// 		IsActive:     "Y",
					// 	},
					// },
				},
				{
					ChildrenParentID: "3",
					ChildrenMenuID:   "2",
					ChildrenMenuName: "Pre-Registrasi",
					ChildrenMenuURL:  "/mcu/preregister",
					// Breadcrumb: []Breadcrumb{
					// 	{
					// 		IDBreadcrumb: "1",
					// 		Title:        "Dashboard",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "2",
					// 		Title:        "Master",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "3",
					// 		Title:        "User",
					// 		IsActive:     "Y",
					// 	},
					// },
				},
			},
		},

		// 5. Master Data
		{
			ID:             "5",
			ParentMenuID:   "4",
			ParentMenuName: "Master Data",
			ParentUrl:      "#",
			ParentIcon:     "",
			Children: []models.ChildrenMenu{
				// * Master User
				{
					ChildrenParentID: "4",
					ChildrenMenuID:   "1",
					ChildrenMenuName: "Master User",
					ChildrenMenuURL:  "/client/md/user",
					// Breadcrumb: []Breadcrumb{
					// 	{
					// 		IDBreadcrumb: "1",
					// 		Title:        "Dashboard",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "2",
					// 		Title:        "Master",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "3",
					// 		Title:        "User",
					// 		IsActive:     "Y",
					// 	},
					// },
				},

				// * Master User Group
				{
					ChildrenParentID: "4",
					ChildrenMenuID:   "2",
					ChildrenMenuName: "Master User Group",
					ChildrenMenuURL:  "/client/md/usergroup",
					// Breadcrumb: []Breadcrumb{
					// 	{
					// 		IDBreadcrumb: "1",
					// 		Title:        "Dashboard",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "2",
					// 		Title:        "Master",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "3",
					// 		Title:        "User Group",
					// 		IsActive:     "Y",
					// 	},
					// },
				},

				// * Master Corporate
				{
					ChildrenParentID: "4",
					ChildrenMenuID:   "3",
					ChildrenMenuName: "Corporate",
					ChildrenMenuURL:  "/client/md/corp",
					// Breadcrumb: []Breadcrumb{
					// 	{
					// 		IDBreadcrumb: "1",
					// 		Title:        "Dashboard",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "2",
					// 		Title:        "Master",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "3",
					// 		Title:        "User Group",
					// 		IsActive:     "Y",
					// 	},
					// },
				},

				// * Test
				{
					ChildrenParentID: "4",
					ChildrenMenuID:   "4",
					ChildrenMenuName: "Test",
					ChildrenMenuURL:  "/client/md/test",
					// Breadcrumb: []Breadcrumb{
					// 	{
					// 		IDBreadcrumb: "1",
					// 		Title:        "Dashboard",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "2",
					// 		Title:        "Master",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "3",
					// 		Title:        "User Group",
					// 		IsActive:     "Y",
					// 	},
					// },
				},

				// * Bahan
				{
					ChildrenParentID: "4",
					ChildrenMenuID:   "5",
					ChildrenMenuName: "Bahan",
					ChildrenMenuURL:  "/client/md/bahan",
					// Breadcrumb: []Breadcrumb{
					// 	{
					// 		IDBreadcrumb: "1",
					// 		Title:        "Dashboard",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "2",
					// 		Title:        "Master",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "3",
					// 		Title:        "User Group",
					// 		IsActive:     "Y",
					// 	},
					// },
				},

				// * Sample Type
				{
					ChildrenParentID: "4",
					ChildrenMenuID:   "6",
					ChildrenMenuName: "Sample Type",
					ChildrenMenuURL:  "/client/sample/type",
					// Breadcrumb: []Breadcrumb{
					// 	{
					// 		IDBreadcrumb: "1",
					// 		Title:        "Dashboard",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "2",
					// 		Title:        "Master",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "3",
					// 		Title:        "User Group",
					// 		IsActive:     "Y",
					// 	},
					// },
				},

				// * Sample Station
				{
					ChildrenParentID: "4",
					ChildrenMenuID:   "7",
					ChildrenMenuName: "Sample Station",
					ChildrenMenuURL:  "/station/sample",
					// Breadcrumb: []Breadcrumb{
					// 	{
					// 		IDBreadcrumb: "1",
					// 		Title:        "Dashboard",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "2",
					// 		Title:        "Master",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "3",
					// 		Title:        "User Group",
					// 		IsActive:     "Y",
					// 	},
					// },
				},

				// * Result Non Lab
				{
					ChildrenParentID: "4",
					ChildrenMenuID:   "8",
					ChildrenMenuName: "Result Non Lab",
					ChildrenMenuURL:  "/client/md/resultnonlab",
					// Breadcrumb: []Breadcrumb{
					// 	{
					// 		IDBreadcrumb: "1",
					// 		Title:        "Dashboard",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "2",
					// 		Title:        "Master",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "3",
					// 		Title:        "User Group",
					// 		IsActive:     "Y",
					// 	},
					// },
				},

				// * Template Fisik
				{
					ChildrenParentID: "4",
					ChildrenMenuID:   "9",
					ChildrenMenuName: "Template Fisik",
					ChildrenMenuURL:  "/client/md/template-fisik",
					// Breadcrumb: []Breadcrumb{
					// 	{
					// 		IDBreadcrumb: "1",
					// 		Title:        "Dashboard",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "2",
					// 		Title:        "Master",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "3",
					// 		Title:        "User Group",
					// 		IsActive:     "Y",
					// 	},
					// },
				},

				// * Pasien
				{
					ChildrenParentID: "4",
					ChildrenMenuID:   "10",
					ChildrenMenuName: "Pasien",
					ChildrenMenuURL:  "/client/md/pasien",
					// Breadcrumb: []Breadcrumb{
					// 	{
					// 		IDBreadcrumb: "1",
					// 		Title:        "Dashboard",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "2",
					// 		Title:        "Master",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "3",
					// 		Title:        "User Group",
					// 		IsActive:     "Y",
					// 	},
					// },
				},

				// * Dokter
				{
					ChildrenParentID: "4",
					ChildrenMenuID:   "11",
					ChildrenMenuName: "Dokter",
					ChildrenMenuURL:  "/client/md/dokter",
					// Breadcrumb: []Breadcrumb{
					// 	{
					// 		IDBreadcrumb: "1",
					// 		Title:        "Dashboard",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "2",
					// 		Title:        "Master",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "3",
					// 		Title:        "User Group",
					// 		IsActive:     "Y",
					// 	},
					// },
				},

				// * Paket
				{
					ChildrenParentID: "4",
					ChildrenMenuID:   "12",
					ChildrenMenuName: "Paket",
					ChildrenMenuURL:  "/client/md/paket",
					// Breadcrumb: []Breadcrumb{
					// 	{
					// 		IDBreadcrumb: "1",
					// 		Title:        "Dashboard",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "2",
					// 		Title:        "Master",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "3",
					// 		Title:        "User Group",
					// 		IsActive:     "Y",
					// 	},
					// },
				},

				// * Harga Single
				{
					ChildrenParentID: "4",
					ChildrenMenuID:   "13",
					ChildrenMenuName: "Harga Single",
					ChildrenMenuURL:  "/client/md/hargasingle",
					// Breadcrumb: []Breadcrumb{
					// 	{
					// 		IDBreadcrumb: "1",
					// 		Title:        "Dashboard",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "2",
					// 		Title:        "Master",
					// 		IsActive:     "N",
					// 	},
					// 	{
					// 		IDBreadcrumb: "3",
					// 		Title:        "User Group",
					// 		IsActive:     "Y",
					// 	},
					// },
				},
			},
		},
	}

	return dummyMenu, nil
}

func GetUserLogin() (models.User, error) {
	a := models.User{
		UserID:       1,
		Username:     "andy",
		UserFullName: "Alfianto Andy P",
		UserPosition: "Software Developer",
	}
	return a, nil
}

func GetTerminologyList(inp models.TerminologyParamv0) ([]models.TerminologyV0, error) {
	logger, _ := zap.NewProduction()
	defer logger.Sync()

	var term []models.TerminologyV0

	query := `
		SELECT
			*
		FROM terminology
		WHERE status_cd = 'normal'
		AND code_system = ?
		AND attribute_path = ?
	`

	logger.Info("QUERY SEARCH TERMINOLOGY",
		zap.String("query search", query),
	)

	if err := dbx.Handlex.Select(&term, query,
		inp.CodeSystem,
		inp.AttributePath); err != nil {
		return nil, fmt.Errorf("error querying database terminology: %v", err)
	}

	return term, nil
}
