package model

import (
	"strings"

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

type Disease struct {
	Id          int64                 `json:"id"`
	Name        string                `json:"name"`
	Symptoms    string                `json:"symptoms"`
	DiseaseType int32                 `json:"disease_type"`
	IsShow      pasturePb.IsShow_Kind `json:"is_show"`
	Remarks     string                `json:"remarks"`
	OperationId int64                 `json:"operation_id"`
	CreatedAt   int64                 `json:"created_at"`
	UpdatedAt   int64                 `json:"updated_at"`
}

func (d *Disease) TableName() string {
	return "disease"
}

type DiseaseSlice []*Disease

func (d DiseaseSlice) ToPB(user []*SystemUser, diseaseTypeList []*ConfigDiseaseType) []*pasturePb.SearchDiseaseList {
	res := make([]*pasturePb.SearchDiseaseList, len(d))
	for i, dl := range d {
		operationName, diseaseTypeName := "", ""
		for _, u := range user {
			if u.Id == dl.OperationId {
				operationName = u.NickName
				break
			}
		}

		for _, dt := range diseaseTypeList {
			if dt.Id == int64(dl.DiseaseType) {
				diseaseTypeName = dt.Name
				break
			}
		}

		res[i] = &pasturePb.SearchDiseaseList{
			Id:              int32(dl.Id),
			Remarks:         dl.Remarks,
			OperationId:     int32(dl.OperationId),
			OperationName:   operationName,
			Name:            dl.Name,
			DiseaseTypeId:   dl.DiseaseType,
			DiseaseTypeName: diseaseTypeName,
			Symptoms:        strings.Split(dl.Symptoms, "|"),
			IsShow:          dl.IsShow,
			CreatedAt:       int32(dl.CreatedAt),
			UpdatedAt:       int32(dl.UpdatedAt),
		}
	}
	return res
}

func (c DiseaseSlice) ToPB2() []*pasturePb.ConfigOptionsList {
	res := make([]*pasturePb.ConfigOptionsList, len(c))
	for i, d := range c {
		res[i] = &pasturePb.ConfigOptionsList{
			Value:    int32(d.Id),
			Label:    d.Name,
			Disabled: true,
		}
	}
	return res
}