package model

import (
	"fmt"
	"reflect"

	"github.com/go-rod/rod"
)

type BordroProperty struct {
	Index int
	Value string
	Id    string
	//DomType string
}

type Bordro struct {
	Sube                              BordroProperty // 0
	Bolum                             BordroProperty //
	TCKimlikNo                        BordroProperty //
	AdiSoyadi                         BordroProperty //
	NormalGun                         BordroProperty //4
	HaftaTatili                       BordroProperty //
	X75                               BordroProperty //
	EksikGunNeden                     BordroProperty //
	ArgeDestekVeTasarim               BordroProperty //
	FazlaMesai                        BordroProperty // 9
	GeceMesaisi                       BordroProperty //10
	BayramMesaisi                     BordroProperty //
	Yol                               BordroProperty //12
	YemekGun                          BordroProperty //13
	YemekTutar                        BordroProperty //
	Aile                              BordroProperty //15
	Cocuk                             BordroProperty //
	Evlenme                           BordroProperty //17
	Dogum                             BordroProperty //18
	Olum                              BordroProperty //19
	Askerlik                          BordroProperty //20
	Ozelsigorta                       BordroProperty //21
	BireyselEmeklilik                 BordroProperty //22
	HayatSigortasi                    BordroProperty //23
	PrimNet                           BordroProperty //24
	PrimBrut                          BordroProperty //
	IkramiyeNet                       BordroProperty //25
	IkramiyeBrut                      BordroProperty //
	KıdemTazminatı                    BordroProperty //28
	IhbarTazminati                    BordroProperty //29
	Bayram                            BordroProperty //30
	Yakacak                           BordroProperty //31
	HuzurHakki                        BordroProperty //32
	HediyeKart                        BordroProperty
	YakitKart                         BordroProperty
	YillikIzin                        BordroProperty
	MaasFarki                         BordroProperty
	AyirilisPaketi                    BordroProperty
	RamazanKumanyasi                  BordroProperty
	TelefonDesteği                    BordroProperty //39
	EkOdemeNet                        BordroProperty
	EkOdemeBrut                       BordroProperty
	IsAramaIzni                       BordroProperty
	Prim2                             BordroProperty //43
	Prim3                             BordroProperty
	Prim4                             BordroProperty
	CalismaIzniHarci                  BordroProperty
	OzeldurumOdenesi                  BordroProperty
	EmekliSandigiCalisanPrimi         BordroProperty
	LisanTazminati                    BordroProperty
	OdulOdenesi                       BordroProperty
	IsSonuTazminati                   BordroProperty
	VergiIstisnasiEkOdeme             BordroProperty
	KresYardimi                       BordroProperty //53
	EsnekYanHak                       BordroProperty
	AracKullanim                      BordroProperty
	EgitimDesteği                     BordroProperty
	DelegeUcreti                      BordroProperty
	HarcTutarlari                     BordroProperty
	SendikaIscilikFarkUcretleri       BordroProperty
	IsinmaDesteği                     BordroProperty
	SoforlukMesaisi                   BordroProperty
	Avans                             BordroProperty
	Icra                              BordroProperty
	Sendika                           BordroProperty
	HediyeKart2                       BordroProperty
	YemekAyni                         BordroProperty
	RamazanKumanyasiAyni              BordroProperty
	BagimliOSSKesintisi               BordroProperty
	CalismaIzniHarciAyni              BordroProperty
	TrafikCezasiKesintisi             BordroProperty
	BesKesintisi                      BordroProperty
	YakitKart2                        BordroProperty
	GrupBesPersonelPayiKesintisi      BordroProperty
	IstisnadanKaynaklananKesinti      BordroProperty
	EmekliSandigiCalisanPrimKesintisi BordroProperty
	PesinYillikIzinKesintisi          BordroProperty
	TelefonLimitAsimKesintisi         BordroProperty
	ZimmetTamirKesintisi              BordroProperty
	YakitAsimKesintisi                BordroProperty
	DigerAvanslar                     BordroProperty
	DigerKesintiler                   BordroProperty
	ZorunluBesKesintisi               BordroProperty
	ZimmetliBilgisayarTamirUcreti     BordroProperty
	HarcTutarlari2                    BordroProperty
	PrimAvansi                        BordroProperty
	MasrafKesintisi                   BordroProperty
	BireyselEmekPrimi                 BordroProperty //88
	OzelsigortaPrimi                  BordroProperty //89
	DigerIstisnalar                   BordroProperty //90
}

func getPageId(id int) string {
	switch id {
	case 4:
		return "#normalGun0"
	case 5:
		return "#normalGun1" //, "checkbox"
	case 6:
		return ""
	case 7:
		return ""
	case 8:
		return ""
	case 9:
		return "#ekKazancCarpan0"
	case 10:
		return "#ekKazancCarpan1"
	case 11:
		return ""
	case 12:
		return "#ekKazancCarpan3"
	case 13:
		return "#ekKazancCarpan4"
	case 14:
		return ""
	case 15:
		return "#ekKazancDeger5"
	case 16:
		return ""
	case 17:
		return "#ekKazancDeger7"
	case 18:
		return "#ekKazancDeger8"
	case 19:
		return "#ekKazancDeger9"
	case 20:
		return "#ekKazancDeger10"
	case 21:
		return "#ekKazancDeger11"
	case 22:
		return "#ekKazancDeger12"
	case 23:
		return "#ekKazancDeger13"
	case 24:
		return "#ekKazancDeger14" //primNet
	case 25:
		return "#ekKazancDeger15"
	case 26:
		return ""
	case 27:
		return ""
	case 28:
		return "#ekKazancDeger16"
	case 29:
		return "#ekKazancDeger17"
	case 30:
		return "#ekKazancDeger18"
	case 31:
		return "#ekKazancDeger19"
	case 32:
		return "#ekKazancDeger23"
	case 33:
		return ""
	case 34:
		return ""
	case 35:
		return ""
	case 36:
		return ""
	case 37:
		return ""
	case 38:
		return ""
	case 39:
		return "#ekKazancDeger21"
	case 40:
		return ""
	case 41:
		return ""
	case 42:
		return ""
	case 43:
		return "#ekKazancDeger20"
	case 44:
		return ""
	case 45:
		return ""
	case 46:
		return ""
	case 47:
		return ""
	case 48:
		return ""
	case 49:
		return ""
	case 50:
		return ""
	case 51:
		return ""
	case 52:
		return ""
	case 53:
		return "#ekKazancDeger22"
	case 54:
		return ""
	case 55:
		return ""
	case 56:
		return ""
	case 57:
		return ""
	case 58:
		return ""
	case 59:
		return ""
	case 60:
		return ""
	case 61:
		return ""
	case 62:
		return ""
	case 63:
		return ""
	case 64:
		return ""
	case 65:
		return ""
	case 66:
		return ""
	case 67:
		return ""
	case 68:
		return ""
	case 69:
		return ""
	case 70:
		return ""
	case 71:
		return ""
	case 72:
		return ""
	case 73:
		return ""
	case 74:
		return ""
	case 75:
		return ""
	case 76:
		return ""
	case 77:
		return ""
	case 78:
		return ""
	case 79:
		return ""
	case 80:
		return ""
	case 81:
		return ""
	case 82:
		return ""
	case 83:
		return ""
	case 84:
		return ""
	case 85:
		return ""
	case 86:
		return ""
	case 87:
		return ""
	case 88:
		return "#bireyselEmeklilikIstisna"
	case 89:
		return "#ozelSigortaIstisna"
	case 90:
		return "#digerIstisna"
	default:
		return ""
	}
}
func (b *Bordro) FillBordroForm(rodForm *rod.Page) error {
	objValue := reflect.ValueOf(b).Elem()
	objType := objValue.Type()
	for i := 0; i < objValue.NumField(); i++ {
		field := objValue.Field(i)
		fieldName := objType.Field(i).Name
		valueField := field.FieldByName("Value")
		idField := field.FieldByName("Id")
		idValue := idField.Interface().(string)
		if idValue != "" {
			elem, err := rodForm.Element(idField.Interface().(string))
			if err != nil {
				return err
			}
			value := valueField.Interface().(string)
			// switch expression {
			// case "input":
			// 	//elem.Input(value)

			// }
			elem.Input(value)
		}

		fmt.Print(fieldName)
	}
	return nil
}

// BordroProperty structının tipi de olabilir drop checkbox vs ayrı bir fonksiyon çalışabilir getPageId den dönebilirsin
func NewFromExcelLine(rows []string) (*Bordro, error) {
	bordro := Bordro{} // Yeni bir Bordro örneği oluştur
	//her indexi eşitleyebilirsin bordro objesine veya tek
	// Iterate over the fields of MyStruct
	objValue := reflect.ValueOf(&bordro).Elem()
	objType := objValue.Type()
	for i := 0; i < objValue.NumField(); i++ {
		field := objValue.Field(i)
		fieldName := objType.Field(i).Name
		indexField := field.FieldByName("Index")
		valueField := field.FieldByName("Value")
		idField := field.FieldByName("Id")

		if len(rows) > i {
			indexField.SetInt(int64(i))
			valueField.SetString(rows[i])
			idField.SetString(getPageId(i))
		} else {
			indexField.SetInt(int64(i))
			valueField.SetString("")
			idField.SetString(getPageId(i))
		}

		fmt.Print(field)
		fmt.Print(fieldName)
	}
	fmt.Print(objType)
	//bordro.Sube = ExcelCellValue{ExcelIndex: 0}

	return &bordro, nil

}
