/*
 * @description: 编号规则
 * @Author: LanJianRong
 * @Date: 2020-11-27
 * @FilePath: \construction_management\web\viewmodels\rule.go
 */
package viewmodels

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

type Rule struct {
	Id           string `form:"id" json:"id" `
	ProjectId    string `form:"projectId" json:"projectId" `
	BidsectionId string `form:"bidsectionId" json:"bidsectionId" `
	SafeRule     string `form:"safeRule" json:"safeRule" `
	QualityRule  string `form:"qualityRule" json:"qualityRule" `
	ContractRule string `form:"contractRule" json:"contractRule" `
}

// 页面所需字段
type ViewRule struct {
	SafeRule     string `form:"safeRule" json:"safeRule" `
	QualityRule  string `form:"qualityRule" json:"qualityRule" `
	ContractRule string `form:"contractRule" json:"contractRule" `
}

type ValidField struct {
	BidsectionId string `form:"bidsectionId" json:"bidsectionId" `
	Type         string `form:"type" json:"type"`
	Rule         string `form:"rule" json:"rule"`
}

type RuleCode struct {
	Eg   string `from:"eg" json:"eg"`
	Date string `from:"date" json:"date"`
	Text string `from:"text" json:"text"`
	Name string `from:"name" json:"name"`
	Code string `from:"code" json:"code"`
}

func (l ValidField) Validate() error {
	return validation.ValidateStruct(&l,
		validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
	)
}

func (l ValidField) ValidateAuto() error {
	return validation.ValidateStruct(&l,
		validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
		validation.Field(&l.Type, validation.Required.Error("类型不能为空")),
	)
}
