/*
 * @description: 质量巡检-审批
 * @Author: LanJianRong
 * @Date: 2020-12-18
 * @FilePath: \construction_management\web\viewmodels\safe_audit.go
 */
package viewmodels

import (
	"time"

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

type SafeAudit struct {
	Id            string    `form:"id" json:"id"`
	SafeId        string    `form:"safe_id" json:"safe_id"`
	BidsectionId  string    `form:"bidsection_id" json:"bidsection_id"`
	Times         int       `form:"times" json:"times"`
	AuditId       string    `form:"audit_id" json:"audit_id"`
	AuditOrder    int       `form:"audit_order" json:"audit_order"`
	Status        int       `form:"status" json:"status"`
	CreateTime    time.Time `form:"create_time" json:"create_time"`
	EndTime       time.Time `form:"end_time" json:"end_time"`
	Progress      string    `form:"progress" json:"progress"`
	Opinion       string    `form:"opinion" json:"opinion"`
	RectifiedInfo string    `form:"rectifiedInfo" json:"rectifiedInfo"`
}

type HistorySafeAudit struct {
	Id         string    `from:"id" json:"id"`
	Name       string    `from:"name" json:"name"`
	Position   string    `from:"position" json:"position"`
	Createtime time.Time `from:"create_time" json:"create_time"`
	EndTime    time.Time `from:"end_time" json:"end_time"`
	Opinion    string    `from:"opinion" json:"opinion"`
	Status     int       `from:"status" json:"status"`
	Progress   string    `from:"progress" json:"progress"`
}

type LatestAuditorVM struct {
	AuditId  string `fron:"audit_id" json:"audit_id"`
	Status   int    `from:"status" json:"status"`
	Progress string `form:"progress" json:"progress" `
}

// 整改单
type CheckOrderVM struct {
	Name    string    `from:"name" json:"name"`
	EndTime time.Time `from:"end_time" json:"end_time"`
	Opinion string    `from:"opinion" json:"opinion"`
	Status  int       `from:"status" json:"status"`
}

func (l SafeAudit) ValidateAddAuditor() error {
	return validation.ValidateStruct(&l,
		validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
		validation.Field(&l.SafeId, validation.Required.Error("巡检ID不能为空")),
		validation.Field(&l.Times, validation.Required.Error("times不能为空")),
		validation.Field(&l.AuditId, validation.Required.Error("审核人不能为空")),
	)
}

func (l SafeAudit) ValidateClose() error {
	return validation.ValidateStruct(&l,
		validation.Field(&l.Id, validation.Required.Error("记录id不能为空")),
		validation.Field(&l.SafeId, validation.Required.Error("巡检id不能为空")),
	)
}

func (l SafeAudit) ValidateBack() error {
	return validation.ValidateStruct(&l,
		validation.Field(&l.Id, validation.Required.Error("记录id不能为空")),
		validation.Field(&l.SafeId, validation.Required.Error("巡检id不能为空")),
		validation.Field(&l.AuditId, validation.Required.Error("回滚用户不能为空")),
	)
}
func (l SafeAudit) ValidatePass() error {
	return validation.ValidateStruct(&l,
		validation.Field(&l.Id, validation.Required.Error("记录id不能为空")),
		validation.Field(&l.SafeId, validation.Required.Error("巡检id不能为空")),
	)
}

type AuditStart struct {
	SafeId       string   `form:"safe_id" json:"safe_id"`
	BidsectionId string   `form:"bidsection_id" json:"bidsection_id"`
	Times        int      `form:"times" json:"times"`
	Auditors     []string `form:"auditors" json:"auditors"`
	ReAuditors   []string `form:"reAuditors" json:"reAuditors"`
}

func (l AuditStart) ValidateStart() error {
	return validation.ValidateStruct(&l,
		validation.Field(&l.BidsectionId, validation.Required.Error("标段id不能为空")),
		validation.Field(&l.SafeId, validation.Required.Error("巡检id不能为空")),
		validation.Field(&l.Times, validation.Required.Error("审批次数不能为空")),
		validation.Field(&l.Auditors, validation.Required.Error("审批组不能为空")),
		validation.Field(&l.ReAuditors, validation.Required.Error("复查组不能为空")),
	)
}
