/*
 * @description: 安全巡检
 * @Author: LanJianRong
 * @Date: 2020-11-18
 * @FilePath: \construction_management\web\viewmodels\safe.go
 */
package viewmodels

import (
	"time"

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

type Safe struct {
	Id           string `form:"id" json:"id" `
	BidsectionId string `form:"bidsectionId" json:"bidsectionId"`

	Uid              string `form:"uid" json:"uid" `
	Code             string `form:"code" json:"code"`
	CreateTime       string `form:"createTime" json:"createTime"`
	EndTime          string `form:"endTime" json:"endTime"`
	Position         string `form:"position" json:"position"`
	Inspection       string `form:"inspection" json:"inspection"`
	InspectionDetail string `form:"inspectionDetail" json:"inspectionDetail"`
	Demand           string `form:"demand" json:"demand"`
	Status           int    `form:"status" json:"status"`
	PageNo           int    `form:"pageNo" json:"pageNo"`
	PageSize         int    `form:"pageSize" json:"pageSize"`
}
type SafeList struct {
	Id               string `form:"id" json:"id" `
	Code             string `form:"code" json:"code"`
	CreateTime       string `form:"createTime" json:"createTime"`
	Position         string `form:"position" json:"position"`
	Inspection       string `form:"inspection" json:"inspection"`
	InspectionDetail string `form:"inspectionDetail" json:"inspectionDetail"`
	Demand           string `form:"demand" json:"demand"`
	Status           int    `form:"status" json:"status"`
	AuditName        string `form:"auditName" json:"auditName"`
	FileCounts       int64  `from:"fileCounts" json:"fileCounts"`
}

type SafeDetail struct {
	Id           string `form:"id" json:"id" `
	BidsectionId string `form:"bidsectionId" json:"bidsectionId"`

	Code             string                     `form:"code" json:"code"`
	CreateTime       time.Time                  `form:"createTime" json:"createTime"`
	Position         string                     `form:"position" json:"position"`
	Inspection       string                     `form:"inspection" json:"inspection"`
	InspectionDetail string                     `form:"inspectionDetail" json:"inspectionDetail"`
	Demand           string                     `form:"demand" json:"demand"`
	Times            int                        `from:"times" json:"times"`
	Status           int                        `form:"status" json:"status"`
	AuditName        string                     `form:"auditName" json:"auditName"`
	File             FileStruct                 `form:"file" json:"file"`
	Auditors         []Auditors                 `form:"auditors" json:"auditors"`
	AuditHistory     map[int][]HistorySafeAudit `from:"auditHistory" json:"auditHistory"`
	RectifiedInfo    []CheckOrderVM             `from:"rectifiedInfo" json:"rectifiedInfo"`
	LatestdAuditor   *LatestAuditorVM           `from:"latestAuditor" json:"latestAuditor"`
}

// 单独出一个struct方便分页使用
type FileStruct struct {
	Total    int64           `form:"total" json:"total"`
	FileList []AnnexListView `form:"fileList" json:"fileList"`
}
type SafeFile struct {
	FileName    string    `from:"filename" json:"filename"`
	FilePath    string    `from:"filepath" json:"filepath"`
	AccountName string    `from:"account_name" json:"acountName"`
	AccountId   string    `from:"account_id" json:"acountId"`
	CreateTime  time.Time `from:"create_time" json:"createTime"`
}
type Auditors struct {
	Name         string `from:"name" json:"name"`
	Progress     string `from:"progress" json:"progress"`
	AuditorId    string `from:"auditor_id" json:"auditor_id"`
	Position     string `from:"position" json:"position"`
	AuditOrder   int    `from:"audit_order" json:"audit_order"`
	AccountGroup int    `from:"account_group" json:"account_group"`
	Company      string `from:"company" json:"company"`
	Status       int    `from:"status" json:"status"`
	AuditId      string `from:"audit_id" json:"audit_id"`
}

type SafeListAuditRecord struct {
	Name       string `form:"name" json:"name"`
	CreateTime string `form:"create_time" json:"create_time"`
}

func (l Safe) ValidateList() error {
	return validation.ValidateStruct(&l,
		validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
		validation.Field(&l.PageNo, validation.Required.Error("页码不能为空")),
		validation.Field(&l.PageSize, validation.Required.Error("页数不能为空")),
	)
}

func (l Safe) ValidateCreate() error {
	return validation.ValidateStruct(&l,
		validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
		validation.Field(&l.CreateTime, validation.Required.Error("日期不能为空")),
		validation.Field(&l.Code, validation.Required.Error("编号不能为空")),
		validation.Field(&l.Position, validation.Required.Error("检查部位不能为空")),
		validation.Field(&l.Inspection, validation.Required.Error("检查项目不能为空")),
	)
}

func (l Safe) ValidateDelete() error {
	return validation.ValidateStruct(&l,
		validation.Field(&l.Id, validation.Required.Error("检查项目不能为空")),
	)
}
