package contract

import (
	"github.com/beego/beego/v2/client/orm"
	"time"
)

// ContractServiceDetail 合同的服务内容详情，表单数据
type ContractServiceDetail struct {
	Id                int       `orm:"column(id);pk"`
	ContractServiceId int       `description:"合同服务id"`
	ContractId        int       `description:"合同id"`
	ServiceTemplateId int       `description:"服务模板id"`
	Col1              string    `orm:"column(col_1)" description:"第1列数据"`
	Col2              string    `orm:"column(col_2)" description:"第2列数据"`
	Col3              string    `orm:"column(col_3)" description:"第3列数据"`
	Col4              string    `orm:"column(col_4)" description:"第4列数据"`
	Col5              string    `orm:"column(col_5)" description:"第5列数据"`
	Col6              string    `orm:"column(col_6)" description:"第6列数据"`
	Col7              string    `orm:"column(col_7)" description:"第7列数据"`
	CreateTime        time.Time `description:"数据添加时间"`
}

type ServiceTemplateDetailCol2 struct {
	CanEdit  bool   `json:"CanEdit"`
	Type     string `json:"Type"`
	ValueId  []int  `json:"ValueId"`
	Value    string `json:"Value"`
	HeadName string `json:"HeadName"`
	RowName  string `json:"RowName"`
}

// 根据服务模板id获取对应的套餐表格数据详情
func GetContractServiceDetailByTemplateId(serviceTemplateId int) (list []*ContractServiceDetail, err error) {
	o := orm.NewOrm()
	sql := `select * from contract_service_detail where service_template_id = ? and contract_service_id = 0 order by id asc`
	_, err = o.Raw(sql, serviceTemplateId).QueryRows(&list)
	return
}

// GetContractServiceDetailListByServiceId 根据合同服务id获取对应的套餐表格数据详情
func GetContractServiceDetailListByServiceId(contractServiceId int) (list []*ContractServiceDetail, err error) {
	o := orm.NewOrm()
	sql := `select * from contract_service_detail where  contract_service_id = ? order by id asc`
	_, err = o.Raw(sql, contractServiceId).QueryRows(&list)
	return
}

// GetContractServiceDetailListByServiceIds 根据合同服务id集合获取对应的套餐表格数据详情
func GetContractServiceDetailListByServiceIds(contractServiceIds string) (list []*ContractServiceDetail, err error) {
	o := orm.NewOrm()
	sql := `select * from contract_service_detail where  contract_service_id in  (` + contractServiceIds + `) order by id asc`
	_, err = o.Raw(sql).QueryRows(&list)
	return
}

// 根据服务模板id获取对应的套餐表格数据详情
func GetContractServiceDetailList() (list []*ContractServiceDetail, err error) {
	o := orm.NewOrm()
	sql := `select * from contract_service_detail order by id asc`
	_, err = o.Raw(sql).QueryRows(&list)
	return
}
