package dev_services

import (
	"time"

	"cpone/db"
)

func NewServicesXsample(u Xsample, uStore db.AppStore) *ServicesXsample {

	return &ServicesXsample{
		Xsample:      u,
		XsampleStore: uStore,
	}
}

type Xsample struct {
	ID          int       `json:"id"`
	Xsamplename string    `json:"Xsamplename"`
	Email       string    `json:"email"`
	CreatedAt   time.Time `json:"created_at,omitempty"`
}

type ServicesXsample struct {
	Xsample      Xsample
	XsampleStore db.AppStore
}

func (su *ServicesXsample) GetAllXsamples() ([]Xsample, error) {
	query := `SELECT id, Xsamplename, email, created_at FROM Xsamples ORDER BY created_at DESC`

	rows, err := su.XsampleStore.Db.Query(query)
	if err != nil {
		return []Xsample{}, err
	}
	// We close the resource
	defer rows.Close()

	Xsamples := []Xsample{}
	for rows.Next() {
		rows.Scan(
			&su.Xsample.ID,
			&su.Xsample.Xsamplename,
			&su.Xsample.Email,
			&su.Xsample.CreatedAt,
		)

		Xsamples = append(Xsamples, su.Xsample)
	}

	return Xsamples, nil
}

func (su *ServicesXsample) GetXsampleById(id int) (Xsample, error) {

	query := `SELECT id, Xsamplename, email, created_at FROM Xsamples
		WHERE id = ?`

	stmt, err := su.XsampleStore.Db.Prepare(query)
	if err != nil {
		return Xsample{}, err
	}

	defer stmt.Close()

	su.Xsample.ID = id
	err = stmt.QueryRow(
		su.Xsample.ID,
	).Scan(
		&su.Xsample.ID,
		&su.Xsample.Xsamplename,
		&su.Xsample.Email,
		&su.Xsample.CreatedAt,
	)
	if err != nil {
		return Xsample{}, err
	}

	return su.Xsample, nil
}

func (su *ServicesXsample) GetListMenus() ([]MasterMenu, error) {

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

	dummyMenu := []MasterMenu{
		// 1. Dashboard
		{
			ID:             "1",
			ParentMenuID:   "0",
			ParentMenuName: "Dashboard",
			ParentUrl:      "/client/md/dashboard",
			ParentIcon:     "",
			Children: []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: []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: []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: []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: []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
}
