package data_manage

import (
	"eta_gn/eta_api/global"
	"time"
)

type ExcelStyle struct {
	ExcelId          int       `gorm:"column:excel_id;primaryKey"` //`orm:"column(excel_id);pk" gorm:"primaryKey" `
	Name             string    `gorm:"column:name"`
	Color            string    `gorm:"column:color"`
	Row              int       `gorm:"column:row"`
	Colum            int       `gorm:"column:colum"`
	DefaultRowHeight int       `gorm:"column:default_row_height"`
	DefaultColWidth  int       `gorm:"column:default_col_width"`
	CellData         string    `gorm:"column:cell_data"`
	Config           string    `gorm:"column:config"`
	Data             string    `gorm:"column:data"`
	CreateTime       time.Time `gorm:"column:create_time"`
}

type ExcelStyleReq struct {
	ExcelId          int
	Name             string
	Color            string
	Row              int
	Colum            int
	DefaultRowHeight int
	DefaultColWidth  int
	CellData         []interface{}
	Config           interface{}
	Data             [][]interface{}
	Frequency        string `description:"频度"`
	ClassifyId       int    `description:"分类id"`
}

type CellData struct {
	R int
	C int
	V struct {
		Bg interface{} `json:"bg"`
		Bl int         `json:"bl"`
		It int         `json:"it"`
		Ff int         `json:"ff"`
		Fs int         `json:"fs"`
		Fc string      `json:"fc"`
		Ht int         `json:"ht"`
		Vt int         `json:"vt"`
		V  int         `json:"-"`
		Ct struct {
			Fa string `json:"fa"`
			T  string `json:"t"`
		} `json:"ct"`
		M string `json:"m"`
	} `json:"v"`
}

type Data struct {
	Bg interface{} `json:"bg"`
	Bl int         `json:"bl"`
	It int         `json:"it"`
	Ff int         `json:"ff"`
	Fs int         `json:"fs"`
	Fc string      `json:"fc"`
	Ht int         `json:"ht"`
	Vt int         `json:"vt"`
	V  int         `json:"-"`
	Ct struct {
		Fa string `json:"fa"`
		T  string `json:"t"`
	} `json:"ct"`
	M string `json:"m"`
}

type config struct {
	Merge      Merge
	BorderInfo BorderInfo
	Rowlen     Rowlen
}

type Merge struct {
	One35 struct {
		R  int `json:"r"`
		C  int `json:"c"`
		Rs int `json:"rs"`
		Cs int `json:"cs"`
	} `json:"13_5"`
	One37 struct {
		R  int `json:"r"`
		C  int `json:"c"`
		Rs int `json:"rs"`
		Cs int `json:"cs"`
	} `json:"13_7"`
	One42 struct {
		R  int `json:"r"`
		C  int `json:"c"`
		Rs int `json:"rs"`
		Cs int `json:"cs"`
	} `json:"14_2"`
	One510 struct {
		R  int `json:"r"`
		C  int `json:"c"`
		Rs int `json:"rs"`
		Cs int `json:"cs"`
	} `json:"15_10"`
}

type BorderInfo struct {
	RangeType string `json:"rangeType"`
	Value     struct {
		RowIndex int `json:"row_index"`
		ColIndex int `json:"col_index"`
		L        struct {
			Style int    `json:"style"`
			Color string `json:"color"`
		} `json:"l"`
		R struct {
			Style int    `json:"style"`
			Color string `json:"color"`
		} `json:"r"`
		T struct {
			Style int    `json:"style"`
			Color string `json:"color"`
		} `json:"t"`
		B struct {
			Style int    `json:"style"`
			Color string `json:"color"`
		} `json:"b"`
	} `json:"value"`
}

type Rowlen struct {
	Num0  int `json:"0"`
	Num1  int `json:"1"`
	Num2  int `json:"2"`
	Num3  int `json:"3"`
	Num4  int `json:"4"`
	Num5  int `json:"5"`
	Num6  int `json:"6"`
	Num7  int `json:"7"`
	Num8  int `json:"8"`
	Num9  int `json:"9"`
	Num10 int `json:"10"`
	Num11 int `json:"11"`
	Num12 int `json:"12"`
	Num13 int `json:"13"`
	Num14 int `json:"14"`
	Num15 int `json:"15"`
	Num16 int `json:"16"`
	Num17 int `json:"17"`
	Num18 int `json:"18"`
	Num19 int `json:"19"`
	Num20 int `json:"20"`
	Num21 int `json:"21"`
	Num22 int `json:"22"`
	Num23 int `json:"23"`
	Num24 int `json:"24"`
	Num25 int `json:"25"`
	Num26 int `json:"26"`
	Num27 int `json:"27"`
	Num28 int `json:"28"`
	Num29 int `json:"29"`
}

type ExcelEdbdataMapping struct {
	MappingId  int `gorm:"primaryKey" `
	ExcelId    int64
	ClassifyId int
	Frequency  string
	TradeCode  string
	CreateTime time.Time
}

func GetExcelEdbdataMappingByTradeCode(classifyId int, frequency string) (excelId *int, err error) {
	sql := `SELECT excel_id FROM excel_edbdata_mapping WHERE classify_id = ? AND frequency=?`
	err = global.DmSQL["edb"].Raw(sql, classifyId, frequency).Scan(&excelId).Error

	return
}

func GetExcelStyleById(excelId int) (item *ExcelStyle, err error) {
	sql := `SELECT * FROM excel_style WHERE excel_id = ? `
	err = global.DmSQL["edb"].Raw(sql, excelId).First(&item).Error

	return
}

type Ct struct {
	Fa string `json:"fa"`
	T  string `json:"t"`
}

// ManualEdbExcelStyleEditReq
// @Description: 手工数据录入编辑(Excel样式)
type ManualEdbExcelStyleEditReq struct {
	EdbName string
	Data    []struct {
		Date  string
		Value float64
	}
	TradeCode  string `description:"指标编码"`
	Unit       string `description:"单位"`
	Frequency  string `description:"频度"`
	ClassifyId int    `description:"分类id"`
}