package model

import "fmt"

type ShiftViewResponse struct {
	ShiftOverview map[string]*OverviewEle
	ShiftList     TShiftList
	Week          int
	StartDate     string
	EndDate       string
	FireMasters   []string
}

type OverviewEle struct {
	Persons     []string
	Description string
}

type TShiftList map[string][]*EWPair

type EWPair struct {
	EngineerId int
	Name       string
	EnName     string
	Team       string
	WeekId     float32
	CategoryId int
	Week       string // offset to offset2
	OnDuty     bool
	Changeable bool
}

type TemplateData struct {
	ShiftOverview map[string]*OverviewEle
	ShiftList     TShiftList
	StartDate     string
	EndDate       string
}

type CategoryPage struct {
	CategoryId int
	ShiftList  TShiftList
	Availables AvailableSlice
	Robin      []string
	Teams      []*Team
}

type Team struct {
	TeamId   int
	TeamName string
}

type AvailablePerson struct {
	TeamName       string `gorm:"column:team_name"`
	EngineerId     int    `gorm:"column:engineer_id"`
	EngineerName   string `gorm:"column:engineer_name"`
	Contribution   int    `gorm:"column:contribution"`
	EngineerEnName string `gorm:"column:engineer_en_name"`
	Experience     int    `gorm:"column:experience"`
}

type AvailableSlice []*AvailablePerson

func (t AvailableSlice) String() string {
	res := ""
	for _, v := range t {
		res += "{ " + fmt.Sprint(v.EngineerId) + ": "
		res += fmt.Sprint(v.Contribution) + " }"
	}
	return res
}

func (a AvailableSlice) Len() int { return len(a) }
func (a AvailableSlice) Less(i, j int) bool {
	if a[i].Contribution == a[j].Contribution {
		return a[i].EngineerId <= a[j].EngineerId
	} else {
		return a[i].Contribution <= a[j].Contribution
	}
}
func (a AvailableSlice) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
