/*
 * @description: 权限相关
 * @Author: CP
 * @Date: 2020-12-25 14:58:52
 * @FilePath: \construction_management\web\viewmodels\permission.go
 */

package viewmodels

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

type Permission struct {
	BidsectionId string `form:"bidsectionId" json:"bidsectionId"`
	AccountId    string `form:"accountId" json:"accountId"`

	ContractAdd    int `form:"contractAdd" json:"contractAdd"`
	ContractDelete int `form:"contractDelete" json:"contractDelete"`
	ContractAccess int `form:"contractAccess" json:"contractAccess"`

	SafeAdd    int `form:"safeAdd" json:"safeAdd"`
	SafeDelete int `form:"safeDelete" json:"safeDelete"`
	SafeAccess int `form:"safeAccess" json:"safeAccess"`

	QualityAdd    int `form:"qualityAdd" json:"qualityAdd"`
	QualityDelete int `form:"qualityDelete" json:"qualityDelete"`
	QualityAccess int `form:"qualityAccess" json:"qualityAccess"`

	BidsectionType int `form:"bidsectionType" json:"bidsectionType"`
}

type PermissionView struct {
	ContractPermission string `from:"contract_permission" json:"contract"`
	QualityPermission  string `from:"quality_permission" json:"quality"`
	SafePermission     string `from:"safe_permission" json:"safe"`
}

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

func (l Permission) ValidateType() error {
	return validation.ValidateStruct(&l,
		validation.Field(&l.BidsectionType, validation.In(0, 1, 2).Error("未找到相关请求类型")),
	)
}
func (l Permission) ValidateSinglePermission() error {
	return validation.ValidateStruct(&l,
		validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
	)
}
