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:"-"`         //"当前填写的值"
	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
	Code         string          `json:"code" valid:"Required; MaxSize(6)"`
	ChanceTypeId int             `json:"chanceTypeId" valid:"Required;"` //机会类型编号
	Name         string          `json:"name" valid:"Required;"`
	Doc          string          `json:"doc"`
	Icon         string          `json:"icon" valid:"Required;"`
	InputList    []*InputElement `json:"inputList" valid:"Required;"`
}

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

/*TemplateList */
type TemplateListRequest struct {
}
type TemplateListResponse struct {
	List []*TemplateList `json:"list"`
	//ResponsePageInfo
}

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

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

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

/*TemplateEditVisible */
type TemplateEditVisibleRequest struct {
	Id            int             `json:"id"` //模板编号
	VisibleObject []VisibleObject `json:"visibleObject" valid:"Required"`
}
type TemplateEditVisibleResponse struct {
}

/*TemplateAddCategory */
type TemplateOperateCategoryRequest struct {
	Id   int    `json:"id"`
	Name string `json:"name" valid:"Required"`
	Code string `json:"code" valid:"Required"`
	Icon string `json:"icon"`
}
type TemplateOperateCategoryResponse struct {
}

/*TemplateGet */
type TemplateGetRequest struct {
	Id int `json:"id" valid:"Required"`
}
type TemplateGetResponse struct {
	Template Template `json:"template"`
	Example  string   `json:"example"` //示例`
}

/*TemplateEditSort */
type TemplateEditSortRequest struct {
	ChanceTypeId int        `json:"chance_type_id"` //机会类型编号
	List         []SortItem `json:"list"`           //需要排序的列表
}
type TemplateEditSortResponse struct {
}

//排序项
type SortItem struct {
	Id      int `json:"id"`
	SortNum int `json:"sort_num"`
}

/*TemplateEditEnable 模板启用*/
type TemplateEditEnableRequest struct {
	TemplateId int  `json:"id" valid:"Required"`
	Enabled    int8 `json:"enabled"` //启用状态 1 启用 0 禁用
}
type TemplateEditEnableResponse struct {
}

/*TemplateDelete 删除模板*/
type TemplateDeleteRequest struct {
	TemplateId int `json:"id" valid:"Required"`
}
type TemplateDeleteResponse struct {
}

/*TemplateDeleteCategory  删除一级分类*/
type TemplateDeleteCategoryRequest struct {
	ChanceTypeId int `json:"id" valid:"Required"`
}
type TemplateDeleteCategoryResponse struct {
}

/*CategoryEditSort 一级分类排序*/
type CategoryEditSortRequest struct {
	List []SortItem `json:"list"` //需要排序的列表
}
type CategoryEditSortResponse struct {
}