package model

import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"

type CalvingCalf struct {
	Id            int64                  `json:"id"`
	CalvingId     int64                  `json:"calvingId"`
	CowId         int64                  `json:"cow_id"`
	BirthAt       int64                  `json:"birthAt"`
	MotherId      int64                  `json:"motherId"`
	EarNumber     string                 `json:"earNumber"`
	Sex           pasturePb.Genders_Kind `json:"sex"`
	CowKind       pasturePb.CowKind_Kind `json:"cowKind"`
	BirthWeight   int64                  `json:"birthWeight"`
	IsLive        pasturePb.IsShow_Kind  `json:"isLive"`
	IsAdoption    pasturePb.IsShow_Kind  `json:"isAdoption"`
	PenId         int32                  `json:"penId"`
	WeaningAt     int64                  `json:"weaningAt"`
	CurrentWeight int64                  `json:"currentWeight"`
	Remarks       string                 `json:"remarks"`
	CreatedAt     int64                  `json:"createdAt"`
	UpdatedAt     int64                  `json:"updatedAt"`
}

func (e *CalvingCalf) TableName() string {
	return "calving_calf"
}

func NewEventCalvingCalf(motherId, calvingId int64, req *pasturePb.EventCalving) []*CalvingCalf {
	calvingCalfList := make([]*CalvingCalf, 0)
	for _, v := range req.CalfItemList {
		isAdoption := v.IsAdoption
		if v.IsLive == pasturePb.IsShow_No {
			isAdoption = pasturePb.IsShow_No
		}
		calvingCalfList = append(calvingCalfList, &CalvingCalf{
			EarNumber:     v.EarNumber,
			CalvingId:     calvingId,
			CowId:         int64(v.CowId),
			BirthAt:       int64(req.CalvingAt),
			PenId:         v.PenId,
			BirthWeight:   int64(v.Weight * 1000),
			CurrentWeight: int64(v.Weight * 1000),
			Sex:           v.Sex,
			MotherId:      motherId,
			Remarks:       v.Remarks,
			IsAdoption:    isAdoption,
			IsLive:        v.IsLive,
		})
	}
	return calvingCalfList
}