/*
 * @description:合同项目节-视图层
 * @Author: CP
 * @Date: 2020-11-02 15:18:59
 * @FilePath: \design_quantity\web\viewmodels\tree_section_contract.go
 */
package viewmodels

import (
	validation "github.com/go-ozzo/ozzo-validation/v3"
)

// ElderBrother 为true 有前一个兄弟节点，可上移和下降
// IsEnd 为true 不能下移

type TreeSectionContract struct {
	Id string `form:"id" json:"id" `
	// File file   `form:"File" json:"File" `
	// TreeType     int    `form:"treeType" json:"treeType"`
	ParentId    string `form:"parentId" json:"parentId"`
	Name        string `form:"name" json:"name"`
	Depth       int    `form:"depth" json:"depth"`
	Serial      int    `form:"serial" json:"serial"`
	Attribution string `form:"attribution" json:"attribution"`
	Code        string `form:"code" json:"code"`
	Code2       string `form:"code2" json:"code2"`
	// ProjectId    string `form:"projectId" json:"projectId"`
	// BidsectionId string `form:"bidsectionId" json:"bidsectionId"`
	ContractId string `form:"contractId" json:"contractId"`

	// ContractName     string `form:"contractName" json:"contractName"`
	// ContractCode     string `form:"contractCode" json:"contractCode"`
	// ContractPrice    string `form:"contractPrice" json:"contractPrice"`
	// ContractReturned string `form:"contractReturned" json:"contractReturned"`
	// ContractsPaid    string `form:"contractsPaid" json:"contractsPaid"`
	// ContractStatus   int    `form:"contractStatus" json:"contractStatus"`
	// ContractLocking  int    `form:"contractLocking" json:"contractLocking"`

	CreateTime string                 `form:"createTime" json:"createTime"`
	Children   []*TreeSectionContract `json:"children"`

	// TemplateNumber int    `form:"templateNumber" json:"templateNumber"`
	Operation    string `form:"operation" json:"operation"`
	ElderBrother bool   `form:"elderBrother" json:"elderBrother"`
	IsEnd        bool   `form:"isEnd" json:"isEnd"`
}

type TreeSectionDetail struct {
	Name    string `from:"name" json:"name"`
	Content string `from:"content" json:"content"`
}

func (l TreeSectionContract) ValidateDepth() error {
	return validation.ValidateStruct(&l,
		validation.Field(&l.Id, validation.Required.Error("项目节ID不能为空")),
		// validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
		validation.Field(&l.Operation, validation.Required.Error("操作名称不能为空"), validation.In("upDepth", "downDepth", "upSerial", "downSerial").Error("未找到相关操作")),
	)
}

func (l TreeSectionContract) ValidateSectionNot() error {
	return validation.ValidateStruct(&l) // validation.Field(&l.TreeType, validation.In(0, 1).Error("请输入数字0或1")),
	// validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),

}

func (l TreeSectionContract) ValidateTemplate() error {
	return validation.ValidateStruct(&l) // validation.Field(&l.TemplateNumber, validation.Required.Error("模板号不能为空"), validation.In(1, 2).Error("未找到相关模板")),
	// validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),

}

func (l TreeSectionContract) ValidateSectionAdd() error {
	return validation.ValidateStruct(&l,
		validation.Field(&l.Id, validation.Required.Error("项目节ID不能为空")),
		// validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
		// validation.Field(&l.Name, validation.Required.Error("项目节名称不能为空")),
	)
}

func (l TreeSectionContract) ValidateSectionDelete() error {
	return validation.ValidateStruct(&l,
		validation.Field(&l.Id, validation.Required.Error("项目节ID不能为空")),
		// validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
	)
}

//is.Int.Error("请检查输入是否是整形")  validation.Match(regexp.MustCompile("^[0-9]*$")).Error("请检查输入是否是整形")
func (l TreeSectionContract) ValidateSectionSerial() error {
	return validation.ValidateStruct(&l,
		validation.Field(&l.Id, validation.Required.Error("项目节ID不能为空")),
		// validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
		validation.Field(&l.Serial, validation.Required.Error("序号不能为空")),
	)
}

func (l TreeSectionContract) ValidateFile() error {
	return validation.ValidateStruct(&l,
		validation.Field(&l.Id, validation.Required.Error("项目节ID不能为空")),
		// validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
		validation.Field(&l.ContractId, validation.Required.Error("附件不能为空")),
	)
}

// func (l TreeSectionContract) ValidRuleGet() error {
// 	return validation.ValidateStruct(&l,
// 		validation.Field(&l.Id, validation.Required.Error("项目节ID不能为空")),
// 		validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
// 	)
// }

// Isfolder int `form:"isfolder" json:"isfolder"`

// 	UpdateTime     string `form:"updateTime" json:"updateTime"`
// 	TargetFolderId string `form:"targetFolderId" json:"targetFolderId"`
// 	Ancounts       int    `form:"ancounts" json:"ancounts"`

// 	Csrf string `form:"csrf" json:"csrf"`
// 	// Leaf        bool    `json:"leaf" `
// 	HasFolder   bool    `json:"hasFolder" `
// 	IsBid       bool    `json:"isBid" `
// 	IsEnd       bool    `json:"isEnd"`
// 	ChildsTotal int     `json:"childsTotal"`
