/*
 * @description:合同 视图
 * @Author: CP
 * @Date: 2020-11-11 11:19:30
 * @FilePath: \construction_management\web\viewmodels\contract.go
 */
package viewmodels

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

type Contracts struct {
	Id            string `form:"id" json:"id" `
	TreeId        string `form:"treeId" json:"treeId" `
	ContractsType int    `form:"contractsType" json:"contractsType" `
	ProjectId     string `form:"projectId" json:"projectId" `
	BidsectionId  string `form:"bidsectionId" json:"bidsectionId" `
	Name          string `form:"name" json:"name" `
	Code          string `form:"code" json:"code" `
	Price         string `form:"price" json:"price" `
	Returned      string `form:"returned" json:"returned" `
	Paid          string `form:"paid" json:"paid" `
	Status        int    `form:"status" json:"status" `
	Locking       int    `form:"locking" json:"locking" `
	CreateTime    string `form:"createTime" json:"createTime" `
	UpdateTime    string `form:"updateTime" json:"updateTime" `

	Content      string `form:"content" json:"content" `
	PartyA       string `form:"partyA" json:"partyA" `
	PartyASigner string `form:"partyASigner" json:"partyASigner" `
	PartyB       string `form:"partyB" json:"partyB" `
	PartyBSigner string `form:"partyBSigner" json:"partyBSigner" `
	SignerTime   string `form:"signerTime" json:"signerTime" `
	Remarks      string `form:"remarks" json:"remarks" `
}

// 验证方法
func (l Contracts) ValidateAdd() error {
	return validation.ValidateStruct(&l,
		validation.Field(&l.TreeId, validation.Required.Error("项目节ID不能为空")),
		validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
		validation.Field(&l.Code, validation.Required.Error("合同编号不能为空")),
		validation.Field(&l.Name, validation.Required.Error("名称不能为空")),
		//validation.Field(&l.ContractsType, validation.Required.Error("合同类型不能为空"), validation.In(1, 2).Error("未找到相关合同类型")),
		validation.Field(&l.Price, validation.Required.Error("合同金额不能为空")),
	)
}

func (l Contracts) ValidateEdi() error {
	return validation.ValidateStruct(&l,
		validation.Field(&l.TreeId, validation.Required.Error("项目节ID不能为空")),
		validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
		validation.Field(&l.Name, validation.Required.Error("名称不能为空")),
		validation.Field(&l.Content, validation.Required.Error("合同内容不能为空")),
		validation.Field(&l.Price, validation.Required.Error("合同金额不能为空")),

		validation.Field(&l.PartyA, validation.Required.Error("甲方名称不能为空")),
		validation.Field(&l.PartyASigner, validation.Required.Error("甲方签约人不能为空")),
		validation.Field(&l.PartyB, validation.Required.Error("乙方不能为空")),
		validation.Field(&l.PartyBSigner, validation.Required.Error("乙方签约人不能为空")),
		validation.Field(&l.SignerTime, validation.Required.Error("合同签约日期不能为空")),
	)
}

func (l Contracts) ValidateDel() error {
	return validation.ValidateStruct(&l,
		validation.Field(&l.Id, validation.Required.Error("合同ID不能为空")),
		validation.Field(&l.TreeId, validation.Required.Error("项目节ID不能为空")),
		validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
	)
}

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