package protocol

import "sort"

//输入框类型
const (
	inputTypeCheck string = "check-box" //多选宽
	inputTypeText  string = "text"      //单行文本宽
	InputTypeRedio string = "redio"     //单选框
)

//InputElement 自定义表单项
type InputElement struct {
	Id           int    `json:"id"`
	Sort         int    `json:"sort"`      //排序
	Lable        string `json:"lable"`     //标题
	InputType    string `json:"inputType"` //输入类型
	Required     int    `json:"required"`  //是否必填
	CurrentValue string `json:"value"`     //"当前填写的值"
	SectionType  int8   `json:"sectionType"`

	ValueList   string `json:"-"` //输入候选值 value_list
	Placeholder string `json:"-"` //帮助用户填写输入字段的提示 Placeholder
	Disable     bool   `json:"-"` //"显示隐藏",
}

//自定义表单
type CustomForm []InputElement

var (
	_ sort.Interface = new(CustomForm)
)

//实现排序接口
func (a CustomForm) Len() int      { return len(a) }
func (a CustomForm) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a CustomForm) Less(i, j int) bool {
	return a[i].Sort < a[j].Sort
}

//IValidateInput 自定义输入项校验接口
type IValidateInput interface {
	ValidateInput() error  //校验当前输入值
	ValidateConfig() error //校验自定义的输入项设置
}

type ValidateInputText struct {
	InputElement
}

var (
	_ IValidateInput = ValidateInputText{}
)

func (input ValidateInputText) ValidateInput() error {
	return nil
}
func (input ValidateInputText) ValidateConfig() error {
	return nil
}

//ValidateInputRedio 单选项校验
type ValidateInputRedio struct {
	InputElement
}

var (
	_ IValidateInput = ValidateInputRedio{}
)

func (input ValidateInputRedio) ValidateInput() error {
	return nil
}

func (input ValidateInputRedio) ValidateConfig() error {
	return nil
}

/***********审核模板管理**********/
/*TemplateAdd */
type TemplateAddRequest struct {
	Template Template `json:"template"`
	Example  string   `json:"example"` //示例
}
type TemplateAddResponse struct {
}

type Template struct {
	Id           int64           `json:"id"`           //创建时 0
	ChanceTypeId int             `json:"chanceTypeId"` //机会类型编号
	Name         string          `json:"name"`
	Doc          string          `json:"doc"`
	Icon         string          `json:"icon"`
	InputList    []*InputElement `json:"inputList"`
}

/*TemplateUpdate */
type TemplateUpdateRequest struct {
	Template Template `json:"template"`
	Example  string   `json:"example"` //示例`
}
type TemplateUpdateResponse struct {
}

/*TemplateList */
type TemplateListRequest struct {
}
type TemplateListResponse struct {
}

type ChanceType struct {
	Id        int             `json:"id"`
	Name      string          `json:"name"`
	Icon      string          `json:"icon"`
	Templates []*TemplateItem `json:"templates"`
}

type TemplateItem struct {
	Id            int64           `json:"id"` //创建时 0
	Name          string          `json:"name"`
	Doc           string          `json:"doc"`
	Icon          string          `json:"icon"`
	EnableStatus  int8            `json:"enableStatus"` //禁用状态
	Sort          int             `json:"sort"`         //序号
	VisibleType   int8            `json:"visibleType"`
	VisibleObject []VisibleObject `json:"visibleObject"`
}

type VisibleObject struct {
	Id   int    `json:"id"`
	Name string `json:"name,omitempty"`
	Type int    //1:部门 2:指定人员
}